<?php

/**
 * 行为分析-转换率
 *
 * @author meng.deng
 */

require_once 'CommonController.php';

class Admin_ActDayDataConversionController extends Admin_CommonController
{
    /**
     * 初始化函数
     * 
     * @return void
     */
    public function init()
    {
        parent::init();
        $this->_model = new Application_Model_ActDayDataConversion();
        //清理测试数据条件
        $this->_whereByClear1 = $this->_model -> getTestSourceIds('a');
        $this->_whereByClear2 = $this->_model -> getTestSourceIds();
        $this->view->title = "管理中心";
    }
    
/**
     * 默认动作
     * 
     * @return void
     */
    public function indexAction()
    {

        
        //设置URL模板以及条件
        $urls = array();
        $vars = array();
        $wheres = array();
        $vars['dateType']  = trim($this->_request->get('dateType')) ? trim($this->_request->get('dateType')) : 1;
        $vars['doType'] = trim($this->_request->get('doType')) ? trim($this->_request->get('doType')) : 1;
        $vars['startTime'] = trim($this->_request->get('startTime'));
        $vars['endTime'] = trim($this->_request->get('endTime'));
        $vars['export']   = trim($this->_request->get('export'))!='' ? trim($this->_request->get('export')) :'no';
        
        if ($vars['dateType']==1){
            $vars['startTime'] = date('Y-m-d',strtotime("-1 day"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==2){
            $vars['startTime'] = date('Y-m-d',strtotime("-8 day"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==3){
            $vars['startTime'] = date('Y-m-d',strtotime("-31 day"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==4){
            $vars['startTime'] = date('Y-m-d',strtotime("-3 months"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==5){
            $vars['startTime'] = '';
            $vars['endTime']   = '';
        }
        
        $urls = $vars;
        $productCode = Application_Model_UserLogin::getInstance()->getUserCurrentProductCode();
        $wheres[] = "`productCode` = '{$productCode}'";
        
        if ($vars['startTime'] != '') {
            $wheres[] = "`date` >= '{$vars['startTime']}' ";
        }
        if ($vars['endTime'] != '') {
            $wheres[] = "`date` <= '{$vars['endTime']}' ";
        }
        
        $wheres[] ="`date`>='2011-10-13'";
        $endDate = date('Y-m-d',strtotime("-1 day"));
        $wheres[] ="`date`<='{$endDate}'";
        $orderBy = "`pv` DESC";
        
        
        if ($vars['doType']==1){ //按渠道
            $wheres[] = $this->_whereByClear1;
            $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
            
            $startappModel = new Application_Model_ActDayDataStartapp();
            $sql = "SELECT code,name,sum(pvStart) as pv,sum(uvStart) as uv FROM `{$startappModel->getTableName()}` AS a LEFT JOIN (SELECT  mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId` FROM `mob_source` AS ms INNER JOIN `mob_member` AS mm ON  ms.memberCode=mm.code   WHERE  ms.productCode='{$productCode}' Group By mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId`) AS b ON a.sourceId = b.sourceId AND a.sourceSubId=b.sourceSubId  {$where} GROUP BY code,name ORDER BY {$orderBy}";
            $startappRows = $startappModel ->getAdapter()->fetchAll($sql);
            
            
            //商品详情页
            $pagevisitModel = new Application_Model_ActDayDataPagevisit();
            $sql = "SELECT code,name,sum(pv) as pv,sum(uv) as uv FROM `{$pagevisitModel->getTableName()}` AS a LEFT JOIN (SELECT  mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId` FROM `mob_source` AS ms INNER JOIN `mob_member` AS mm ON  ms.memberCode=mm.code   WHERE  ms.productCode='{$productCode}' Group By mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId`) AS b ON a.sourceId = b.sourceId  AND a.sourceSubId=b.sourceSubId  {$where} AND pageId='1007' GROUP BY code,name ORDER BY {$orderBy}";
            $productInfoRows = $pagevisitModel ->getAdapter()->fetchAll($sql);
            $reProductInfoRows = array();
            foreach ($productInfoRows as $key=>$row){
                $reProductInfoRows[$row['code']]['pv'] = $row['pv'];
                $reProductInfoRows[$row['code']]['uv'] = $row['uv'];
            }
            
            //结算中心
            $pagevisitModel = new Application_Model_ActDayDataPagevisit();
            $sql = "SELECT code,name,sum(pv) as pv,sum(uv) as uv FROM `{$pagevisitModel->getTableName()}` AS a LEFT JOIN (SELECT  mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId` FROM `mob_source` AS ms INNER JOIN `mob_member` AS mm ON  ms.memberCode=mm.code   WHERE  ms.productCode='{$productCode}' Group By mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId`) AS b ON a.sourceId = b.sourceId  AND a.sourceSubId=b.sourceSubId  {$where} AND pageId='1012' GROUP BY code,name ORDER BY {$orderBy}";
            $toCountRows = $pagevisitModel ->getAdapter()->fetchAll($sql);
            $reToCountRows = array();
            foreach ($toCountRows as $key=>$row){
                $reToCountRows[$row['code']]['pv'] = $row['pv'];
                $reToCountRows[$row['code']]['uv'] = $row['uv'];
            }
            
            //加入购物车
            $sql = "SELECT code,name,sum(pv) as pv,sum(uv) as uv FROM `{$this ->_model->getTableName()}` AS a LEFT JOIN (SELECT  mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId` FROM `mob_source` AS ms INNER JOIN `mob_member` AS mm ON  ms.memberCode=mm.code   WHERE  ms.productCode='{$productCode}' Group By mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId`) AS b ON a.sourceId = b.sourceId  AND a.sourceSubId=b.sourceSubId  {$where} AND pageId='1003' GROUP BY code,name ORDER BY {$orderBy}";
            $shoppingRows = $this ->_model ->getAdapter()->fetchAll($sql);
            $reShoppingRows = array();
            foreach ($shoppingRows as $key=>$row){
                $reShoppingRows[$row['code']]['pv'] = $row['pv'];
                $reShoppingRows[$row['code']]['uv'] = $row['uv'];
            }
            
            //提交订单
            $sql = "SELECT code,name,sum(pv) as pv,sum(uv) as uv FROM `{$this ->_model->getTableName()}` AS a LEFT JOIN (SELECT  mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId` FROM `mob_source` AS ms INNER JOIN `mob_member` AS mm ON  ms.memberCode=mm.code   WHERE  ms.productCode='{$productCode}' Group By mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId`) AS b ON a.sourceId = b.sourceId  AND a.sourceSubId=b.sourceSubId  {$where} AND pageId='1007' GROUP BY code,name ORDER BY {$orderBy}";
            $orderRows = $this ->_model ->getAdapter()->fetchAll($sql);
            $reOrderRows = array();
            foreach ($orderRows as $key=>$row){
                $reOrderRows[$row['code']]['pv'] = $row['pv'];
                $reOrderRows[$row['code']]['uv'] = $row['uv'];
            }
            
            //合计
            $countStartApp = array();
            $countStartApp['pvStart'] = 0;
            $countStartApp['uvStart'] = 0;
            foreach($startappRows as $key=>$row) {
                $countStartApp['pvStart'] = $countStartApp['pvStart'] + $row['pv'];
                $countStartApp['uvStart'] = $countStartApp['uvStart'] + $row['uv'];
            }
            
            $reRows = array();
            foreach($startappRows as $key=>$row) {
                
                //启动所占比例 
                $reRows[$row['code']]['pvStartPercent'] = $countStartApp['pvStart']>0 ? number_format($row['pv']/$countStartApp['pvStart'],4)*100 : 0;
                $reRows[$row['code']]['uvStartPercent'] = $countStartApp['uvStart']>0 ? number_format($row['uv']/$countStartApp['uvStart'],4)*100 : 0;
                
                //启动次数
                $reRows[$row['code']]['code'] = $row['code'];
                $reRows[$row['code']]['name'] = $row['name'];
                $reRows[$row['code']]['pvStart'] = $row['pv'];
                $reRows[$row['code']]['uvStart'] = $row['uv'];
                
                //商品详情页
                $reRows[$row['code']]['pvProductInfo'] = 0;
                if(isset($reProductInfoRows[$row['code']]['pv'])){
                    $reRows[$row['code']]['pvProductInfo'] = $reProductInfoRows[$row['code']]['pv'];
                }
                $reRows[$row['code']]['uvProductInfo'] = 0;
                if(isset($reProductInfoRows[$row['code']]['uv'])){
                    $reRows[$row['code']]['uvProductInfo'] = $reProductInfoRows[$row['code']]['uv'];
                }
                
                //结算中心
                $reRows[$row['code']]['pvToCount'] = 0;
                if(isset($reToCountRows[$row['code']]['pv'])){
                    $reRows[$row['code']]['pvToCount'] = $reToCountRows[$row['code']]['pv'];
                }
                $reRows[$row['code']]['uvToCount'] = 0;
                if(isset($reToCountRows[$row['code']]['uv'])){
                    $reRows[$row['code']]['uvToCount'] = $reToCountRows[$row['code']]['uv'];
                }
                
                
                //购物车
                $reRows[$row['code']]['pvShopping'] = 0;
                if(isset($reShoppingRows[$row['code']]['pv'])){
                    $reRows[$row['code']]['pvShopping'] = $reShoppingRows[$row['code']]['pv'];
                }
                $reRows[$row['code']]['uvShopping'] = 0;
                if(isset($reShoppingRows[$row['code']]['uv'])){
                    $reRows[$row['code']]['uvShopping'] = $reShoppingRows[$row['code']]['uv'];
                }
                
                //提交订单
                $reRows[$row['code']]['pvOrder'] = 0;
                if(isset($reOrderRows[$row['code']]['pv'])){
                    $reRows[$row['code']]['pvOrder'] = $reOrderRows[$row['code']]['pv'];
                }
                $reRows[$row['code']]['uvOrder'] = 0;
                if(isset($reOrderRows[$row['code']]['uv'])){
                    $reRows[$row['code']]['uvOrder'] = $reOrderRows[$row['code']]['uv'];
                }
                
            }
            
            
            //重组
            //pv
            $rePvArray = array();
            $rePvOtherArray = array();
            $rePvOtherArray['other']['code'] = '';
            $rePvOtherArray['other']['name'] = '';
            $rePvOtherArray['other']['pvStartPercent'] = 0;
            $rePvOtherArray['other']['pvStart'] = 0;
            $rePvOtherArray['other']['pvProductInfo'] = 0;
            $rePvOtherArray['other']['pvToCount'] = 0;
            $rePvOtherArray['other']['pvShopping'] = 0;
            $rePvOtherArray['other']['pvOrder'] = 0;
            $pvOtherCodeArray = array();
            foreach ($reRows as $key => $row){
                if($row['pvStartPercent']<0){
                   $rePvOtherArray['other']['code'] = 'other';
                   $rePvOtherArray['other']['name'] = '其他';
                   $rePvOtherArray['other']['pvStartPercent'] = $rePvOtherArray['other']['pvStartPercent'] + $row['pvStartPercent'];
                   $rePvOtherArray['other']['pvStart'] = $rePvOtherArray['other']['pvStart'] + $row['pvStart'];
                   $rePvOtherArray['other']['pvProductInfo'] = $rePvOtherArray['other']['pvProductInfo'] + $row['pvProductInfo'];
                   $rePvOtherArray['other']['pvToCount'] = $rePvOtherArray['other']['pvToCount'] + $row['pvToCount'];
                   $rePvOtherArray['other']['pvShopping'] = $rePvOtherArray['other']['pvShopping'] + $row['pvShopping'];
                   $rePvOtherArray['other']['pvOrder'] = $rePvOtherArray['other']['pvOrder'] + $row['pvOrder'];
                   $pvOtherCodeArray[] = "\'{$row['code']}\'";
                } else {
                   $rePvArray[$row['code']]['code'] = $row['code'];
                   $rePvArray[$row['code']]['name'] = $row['name'];
                   $rePvArray[$row['code']]['pvStartPercent'] =  $row['pvStartPercent'];
                   $rePvArray[$row['code']]['pvStart'] =  $row['pvStart'];
                   $rePvArray[$row['code']]['pvProductInfo'] = $row['pvProductInfo'];
                   $rePvArray[$row['code']]['pvToCount'] = $row['pvToCount'];
                   $rePvArray[$row['code']]['pvShopping'] = $row['pvShopping'];
                   $rePvArray[$row['code']]['pvOrder'] = $row['pvOrder'];
                }
                
            }
            if($rePvOtherArray['other']['pvStart']>0){
                $rePvArray = array_merge($rePvArray,$rePvOtherArray);
            }
            $pvOtherCodeStr = count($pvOtherCodeArray)>0 ? implode(',',$pvOtherCodeArray) : '';
            $this->view->pvOtherCodeStr = $pvOtherCodeStr;
            
            
            
            //合计
            $count = array();
            $count['pv']['pvStart'] = 0;
            $count['pv']['pvStartPercent'] = 0;
            $count['pv']['pvProductInfo'] = 0;
            $count['pv']['pvShopping'] = 0;
            $count['pv']['shoppingPercentInfo'] = 0;
            $count['pv']['pvShoppingNum'] = 0;
            $count['pv']['shoppingNumPercentInfo'] = 0;
            $count['pv']['pvToCount'] = 0;
            $count['pv']['toCountPercentInfo'] = 0;
            $count['pv']['pvOrder'] = 0;
            $count['pv']['orderPercentInfo'] = 0;
            $showArray['pv'] = array();
            foreach($rePvArray as $key=>$row) {
                //转化率 加入购物车
                $shoppingPercent = $row['pvStart']>0 ? number_format($row['pvShopping']/$row['pvStart'],4)*100 : 0 ;
                $shoppingPercent = $shoppingPercent>100 ? 100 : $shoppingPercent ;
                $shoppingPercentInfo =  $shoppingPercent."%";
                
                //转化率 结算中心
                $toCountPercent = $row['pvStart']>0 ? number_format($row['pvToCount']/$row['pvStart'],4)*100 : 0 ;
                $toCountPercent = $toCountPercent>100 ? 100 : $toCountPercent ;
                $toCountPercentInfo =  $toCountPercent."%";
                
                //转化率 提交订单
                $orderPercent = $row['pvStart']>0 ? number_format($row['pvOrder']/$row['pvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                
                //合计
                $count['pv']['pvStart'] = $count['pv']['pvStart'] + $row['pvStart'];
                $count['pv']['pvStartPercent'] = $count['pv']['pvStart']>0 ? '100%' : '0%';
                $count['pv']['pvProductInfo'] = $count['pv']['pvProductInfo'] + $row['pvProductInfo'];
                $count['pv']['pvShopping'] = $count['pv']['pvShopping'] + $row['pvShopping'];
                $countShoppingPercentInfo = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvShopping']/$count['pv']['pvStart'],4)*100 : 0;
                $count['pv']['shoppingPercentInfo'] = $countShoppingPercentInfo.'%';
                $count['pv']['pvShoppingNum'] = $count['pv']['pvShoppingNum'] + $row['pvShopping'];
                $count['pv']['shoppingNumPercentInfo'] = $countShoppingPercentInfo.'%';
                $count['pv']['pvToCount'] = $count['pv']['pvToCount'] + $row['pvToCount'];
                $countToCountPercentInfo = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvToCount']/$count['pv']['pvStart'],4)*100  : 0;;
                $count['pv']['toCountPercentInfo'] = $countToCountPercentInfo.'%';
                $count['pv']['pvOrder'] = $count['pv']['pvOrder'] + $row['pvOrder'];
                $countOrderPercentInfo = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvOrder']/$count['pv']['pvStart'],4)*100  : 0;
                $count['pv']['orderPercentInfo'] = $countOrderPercentInfo.'%';
                
                $showArray['pv'][$key]['code'] = $row['code'];
                $showArray['pv'][$key]['name'] = $row['name'];
                $showArray['pv'][$key]['pvStart'] = $row['pvStart'];
                $showArray['pv'][$key]['pvStartPercent'] = $row['pvStartPercent'].'%';
                $showArray['pv'][$key]['pvProductInfo'] = $row['pvProductInfo'];
                $showArray['pv'][$key]['pvShopping'] =  $row['pvShopping'];
                $showArray['pv'][$key]['shoppingPercentInfo'] = $shoppingPercentInfo;
                $showArray['pv'][$key]['pvShoppingNum'] = $row['pvShopping'];
                $showArray['pv'][$key]['shoppingNumPercentInfo'] = $shoppingPercentInfo;
                $showArray['pv'][$key]['pvToCount'] = $row['pvToCount'];
                $showArray['pv'][$key]['toCountPercentInfo'] = $toCountPercentInfo;
                $showArray['pv'][$key]['pvOrder'] = $row['pvOrder'];
                $showArray['pv'][$key]['orderPercentInfo'] = $orderPercentInfo;
                
            }
            
            $this->view->pvRows = $showArray['pv'];
            //uv
            $reUvArray = array();
            $reUvOtherArray = array();
            $reUvOtherArray['other']['code'] = '';
            $reUvOtherArray['other']['name'] = '';
            $reUvOtherArray['other']['uvStartPercent'] = 0;
            $reUvOtherArray['other']['uvStart'] = 0;
            $reUvOtherArray['other']['uvProductInfo'] = 0;
            $reUvOtherArray['other']['uvToCount'] = 0;
            $reUvOtherArray['other']['uvShopping'] = 0;
            $reUvOtherArray['other']['uvOrder'] = 0;
            $uvOtherCodeArray = array();
            foreach ($reRows as $key => $row){
                if($row['uvStartPercent']<0){
                   $reUvOtherArray['other']['code'] = 'other';
                   $reUvOtherArray['other']['name'] = '其他';
                   $reUvOtherArray['other']['uvStartPercent'] = $reUvOtherArray['other']['uvStartPercent'] + $row['uvStartPercent'];
                   $reUvOtherArray['other']['uvStart'] = $reUvOtherArray['other']['uvStart'] + $row['uvStart'];
                   $reUvOtherArray['other']['uvProductInfo'] = $reUvOtherArray['other']['uvProductInfo'] + $row['uvProductInfo'];
                   $reUvOtherArray['other']['uvToCount'] = $reUvOtherArray['other']['uvToCount'] + $row['uvToCount'];
                   $reUvOtherArray['other']['uvShopping'] = $reUvOtherArray['other']['uvShopping'] + $row['uvShopping'];
                   $reUvOtherArray['other']['uvOrder'] = $reUvOtherArray['other']['uvOrder'] + $row['uvOrder'];
                   $uvOtherCodeArray[] = "\'{$row['code']}\'";
                } else {
                   $reUvArray[$row['code']]['code'] = $row['code'];
                   $reUvArray[$row['code']]['name'] = $row['name'];
                   $reUvArray[$row['code']]['uvStartPercent'] =  $row['uvStartPercent'];
                   $reUvArray[$row['code']]['uvStart'] =  $row['uvStart'];
                   $reUvArray[$row['code']]['uvProductInfo'] = $row['uvProductInfo'];
                   $reUvArray[$row['code']]['uvToCount'] = $row['uvToCount'];
                   $reUvArray[$row['code']]['uvShopping'] = $row['uvShopping'];
                   $reUvArray[$row['code']]['uvOrder'] = $row['uvOrder'];
                }
                
            }
            if($reUvOtherArray['other']['uvStart']>0){
                $reUvArray = array_merge($reUvArray,$reUvOtherArray);
            }
            $uvOtherCodeStr = count($uvOtherCodeArray)>0 ? implode(',',$uvOtherCodeArray) : '';
            $this->view->uvOtherCodeStr = $uvOtherCodeStr;
            
            $count['uv']['uvStart'] = 0;
            $count['uv']['uvStartPercent'] = 0;
            $count['uv']['uvProductInfo'] = 0;
            $count['uv']['productInfoPercentInfo'] = 0;
            $count['uv']['uvShopping'] = 0;
            $count['uv']['shoppingPercentInfo'] = 0;
            $count['uv']['uvOrder'] = 0;
            $count['uv']['orderPercentInfo'] = 0;
            $showArray['uv'] = array();
            foreach($reUvArray as $key=>$row) {
                //转化率 商品详情
                $productInfoPercent = $row['uvStart']>0 ? number_format($row['uvProductInfo']/$row['uvStart'],4)*100 : 0 ;
                $productInfoPercent = $productInfoPercent>100 ? 100 : $productInfoPercent ;
                $productInfoPercentInfo =  $productInfoPercent."%";
                
                //转化率 加入购物车
                $shoppingPercent = $row['uvStart']>0 ? number_format($row['uvShopping']/$row['uvStart'],4)*100 : 0 ;
                $shoppingPercent = $shoppingPercent>100 ? 100 : $shoppingPercent ;
                $shoppingPercentInfo =  $shoppingPercent."%";
                
                //转化率 提交订单
                $orderPercent = $row['uvStart']>0 ? number_format($row['uvOrder']/$row['uvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                //合计
                $count['uv']['uvStart'] = $count['uv']['uvStart'] + $row['uvStart'];
                $count['uv']['uvStartPercent'] = $count['uv']['uvStart']>0 ? '100%' : '0%';
                $count['uv']['uvProductInfo'] = $count['uv']['uvProductInfo'] + $row['uvProductInfo'];
                $countProductInfoPercentInfo = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvProductInfo']/$count['uv']['uvStart'],4)*100 : 0;
                $count['uv']['productInfoPercentInfo'] = $countProductInfoPercentInfo.'%';
                $count['uv']['uvShopping'] = $count['uv']['uvShopping'] + $row['uvShopping'];
                $countShoppingPercentInfo = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvShopping']/$count['uv']['uvStart'],4)*100 : 0;
                $count['uv']['shoppingPercentInfo'] = $countShoppingPercentInfo.'%';
                $count['uv']['uvOrder'] = $count['uv']['uvOrder'] + $row['uvOrder'];
                $countOrderPercentInfo = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvOrder']/$count['uv']['uvStart'],4)*100  : 0;
                $count['uv']['orderPercentInfo'] = $countOrderPercentInfo.'%';
                
                
                $showArray['uv'][$key]['code'] = $row['code'];
                $showArray['uv'][$key]['name'] = $row['name'];
                $showArray['uv'][$key]['uvStart'] = $row['uvStart'];
                $showArray['uv'][$key]['uvStartPercent'] = $row['uvStartPercent'].'%';
                $showArray['uv'][$key]['uvProductInfo'] = $row['uvProductInfo'];
                $showArray['uv'][$key]['productInfoPercentInfo'] = $productInfoPercentInfo;
                $showArray['uv'][$key]['uvShopping'] =  $row['uvShopping'];
                $showArray['uv'][$key]['shoppingPercentInfo'] = $shoppingPercentInfo;
                $showArray['uv'][$key]['uvOrder'] = $row['uvOrder'];
                $showArray['uv'][$key]['orderPercentInfo'] = $orderPercentInfo;
                
            }
            
            $this->view->uvRows = $showArray['uv'];
            $this->view->countAll = $count;
            
            //导出Excel
            if ($vars['export']=='yes'){
                $exportArray = array();
                $exportNum =1;
                foreach ($showArray['pv'] as $row){
                    $exportNum++;
                    $exportArray['pv']['A'.$exportNum]= $row['name'];
                    $exportArray['pv']['B'.$exportNum]= $row['pvStart'];
                    $exportArray['pv']['C'.$exportNum]= $row['pvStartPercent'];
                    $exportArray['pv']['D'.$exportNum]= $row['pvProductInfo'];
                    $exportArray['pv']['E'.$exportNum]= $row['pvShopping'];
                    $exportArray['pv']['F'.$exportNum]= $row['shoppingPercentInfo'];
                    $exportArray['pv']['G'.$exportNum]= $row['pvShoppingNum'];
                    $exportArray['pv']['H'.$exportNum]= $row['shoppingNumPercentInfo'];
                    $exportArray['pv']['I'.$exportNum]= $row['pvToCount'];
                    $exportArray['pv']['J'.$exportNum]= $row['toCountPercentInfo'];
                    $exportArray['pv']['K'.$exportNum]= $row['pvOrder'];
                    $exportArray['pv']['L'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['pv']['A'.$exportNum]= '总计';
                $exportArray['pv']['B'.$exportNum]= $count['pv']['pvStart'];
                $exportArray['pv']['C'.$exportNum]= $count['pv']['pvStartPercent'];
                $exportArray['pv']['D'.$exportNum]= $count['pv']['pvProductInfo'];
                $exportArray['pv']['E'.$exportNum]= $count['pv']['pvShopping'];
                $exportArray['pv']['F'.$exportNum]= $count['pv']['shoppingPercentInfo'];
                $exportArray['pv']['G'.$exportNum]= $count['pv']['pvShoppingNum'];
                $exportArray['pv']['H'.$exportNum]= $count['pv']['shoppingNumPercentInfo'];
                $exportArray['pv']['I'.$exportNum]= $count['pv']['pvToCount'];
                $exportArray['pv']['J'.$exportNum]= $count['pv']['toCountPercentInfo'];
                $exportArray['pv']['K'.$exportNum]= $count['pv']['pvOrder'];
                $exportArray['pv']['L'.$exportNum]= $count['pv']['orderPercentInfo'];
                
                $exportNum =1;
                foreach ($showArray['uv'] as $row){
                    $exportNum++;
                    $exportArray['uv']['A'.$exportNum]= $row['name'];
                    $exportArray['uv']['B'.$exportNum]= $row['uvStart'];
                    $exportArray['uv']['C'.$exportNum]= $row['uvStartPercent'];
                    $exportArray['uv']['D'.$exportNum]= $row['uvProductInfo'];
                    $exportArray['uv']['E'.$exportNum]= $row['productInfoPercentInfo'];
                    $exportArray['uv']['F'.$exportNum]= $row['uvShopping'];
                    $exportArray['uv']['G'.$exportNum]= $row['shoppingPercentInfo'];
                    $exportArray['uv']['H'.$exportNum]= $row['uvOrder'];
                    $exportArray['uv']['I'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['uv']['A'.$exportNum]= '总计';
                $exportArray['uv']['B'.$exportNum]= $count['uv']['uvStart'];
                $exportArray['uv']['C'.$exportNum]= $count['uv']['uvStartPercent'];
                $exportArray['uv']['D'.$exportNum]= $count['uv']['uvProductInfo'];
                $exportArray['uv']['E'.$exportNum]= $count['uv']['productInfoPercentInfo'];
                $exportArray['uv']['F'.$exportNum]= $count['uv']['uvShopping'];
                $exportArray['uv']['G'.$exportNum]= $count['uv']['shoppingPercentInfo'];
                $exportArray['uv']['H'.$exportNum]= $count['uv']['uvOrder'];
                $exportArray['uv']['I'.$exportNum]= $count['uv']['orderPercentInfo'];
                
                $table = array();
                $table[0]['tableName'] = '页面转化率-按渠道(pv)';
                $table[0]['title'] = array('渠道名称','启动次数','启动次数占比(%)','商品详情页浏览次数','加入购物车次数','加入购物车转化率','加入购物车商品数量','加入购物车商品转化率','进入订单页面次数','进入订单页面转化率','提交订单数量','提交订单转化率');
                $table[0]['con'] = $exportArray['pv'];
                $table[1]['tableName'] = '页面转化率-按渠道(uv)';
                $table[1]['title'] = array('渠道名称','启动人数','启动人数占比(%)','进入商品详情页人数','进入商品详情页转化率','加入购物车人数','加入购物车转化率','提交订单人数','提交订单转化率');
                $table[1]['con'] = $exportArray['uv'];
                $this->_model->excelExport($table,"[{$vars['startTime']}_{$vars['endTime']}]{$productCode}-member-export");
            }
            
            
            
        } elseif ($vars['doType']==2){ //按专题
            $wheres[] = $this->_whereByClear2;
            $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
            
            $topictoorderModel = new Application_Model_ActDayDataTopictoorder();
            $sql = "SELECT eventPageId,eventPageName,pageId,sum(pv) as pv,sum(uv) as uv FROM `{$topictoorderModel->getTableName()}` {$where} GROUP BY eventPageId,eventPageName,pageId ORDER BY {$orderBy}";
            $topictoOrderRows = $topictoorderModel ->getAdapter()->fetchAll($sql);
            $reTopictoOrderRows = array();
            foreach($topictoOrderRows as $key=>$row) {
                $row['eventPageName'] = trim($row['eventPageName']);
                $reTopictoOrderRows[$row['eventPageName']]['pv'] = $row['pv'];
                $reTopictoOrderRows[$row['eventPageName']]['uv'] = $row['uv'];
            }
            
            $topicvisitModel = new Application_Model_ActDayDataTopicvisit();
            $sql = "SELECT pageId,pageName,sum(pv) as pv,sum(uv) as uv FROM `{$topicvisitModel->getTableName()}` {$where} GROUP BY pageId,pageName ORDER BY {$orderBy}";
            $topicvisitRows = $topicvisitModel ->getAdapter()->fetchAll($sql);
            
            $countTopic = array();
            $countTopic['pvTopic'] = 0;
            $countTopic['uvTopic'] = 0;
            foreach($topicvisitRows as $key=>$row) {
                $countTopic['pvTopic'] =  $countTopic['pvTopic'] + $row['pv'];
                $countTopic['uvTopic'] =  $countTopic['uvTopic'] + $row['uv'];
            }
            
            
            $reRows = array();
            foreach($topicvisitRows as $key=>$row) {
                $row['pageName'] = trim($row['pageName']);
                
                 //所占比例 
                $reRows[$row['pageName']]['pvTopicPercent'] = $countTopic['pvTopic']>0 ? number_format($row['pv']/$countTopic['pvTopic'],4)*100 : 0;
                $reRows[$row['pageName']]['uvTopicPercent'] = $countTopic['uvTopic']>0 ? number_format($row['uv']/$countTopic['uvTopic'],4)*100 : 0;
                
                
                //专题浏览
                $reRows[$row['pageName']]['pageName'] = $row['pageName'];
                $reRows[$row['pageName']]['pvTopic'] = $row['pv'];
                $reRows[$row['pageName']]['uvTopic'] = $row['uv'];
                
                //订单
                $reRows[$row['pageName']]['pvOrder'] = 0;
                if(isset($reTopictoOrderRows[$row['pageName']]['pv'])){
                    $reRows[$row['pageName']]['pvOrder'] = $reTopictoOrderRows[$row['pageName']]['pv'];
                }
                $reRows[$row['pageName']]['uvOrder'] = 0;
                if(isset($reTopictoOrderRows[$row['pageName']]['uv'])){
                    $reRows[$row['pageName']]['uvOrder'] = $reTopictoOrderRows[$row['pageName']]['uv'];
                }
                
            }
            
            //重组
            //pv
            $rePvArray = array();
            $rePvOtherArray = array();
            $rePvOtherArray['other']['name'] = '';
            $reUvOtherArray['other']['pvTopicPercent'] = 0;
            $rePvOtherArray['other']['pvTopic'] = 0;
            $rePvOtherArray['other']['pvOrder'] = 0;
            foreach ($reRows as $key => $row){
                if($row['pvTopicPercent']<1){
                   $rePvOtherArray['other']['name'] = '其他';
                   $rePvOtherArray['other']['pvTopic'] = $rePvOtherArray['other']['pvTopic'] + $row['pvTopic'];
                   $rePvOtherArray['other']['pvOrder'] = $rePvOtherArray['other']['pvOrder'] + $row['pvOrder'];
                } else {
                   $rePvArray[$row['pageName']]['name'] = $row['pageName'];
                   $rePvArray[$row['pageName']]['pvTopic'] =  $row['pvTopic'];
                   $rePvArray[$row['pageName']]['pvOrder'] = $row['pvOrder'];
                }
                
            }
            if($rePvOtherArray['other']['pvTopic']>0){
                $rePvArray = array_merge($rePvArray,$rePvOtherArray);
            }
            
            $count = array();
            $count['pv']['pvTopic']  = 0;
            $count['pv']['pvOrder'] = 0;
			$count['pv']['orderPercentInfo'] = 0;
            $showArray['pv'] = array();
            foreach($rePvArray as $key=>$row) {
                $count['pv']['pvTopic'] = $count['pv']['pvTopic']+$row['pvTopic'];
                $count['pv']['pvOrder'] = $count['pv']['pvOrder']+$row['pvOrder'];
                $count['pv']['orderPercentInfo'] = $count['pv']['pvTopic']>0 ? '100%' : '0%';
            }
            
            foreach($rePvArray as $key=>$row) {        
                //占比 提交订单
                $orderPercent = $count['pv']['pvOrder']>0 ? number_format($row['pvOrder']/$count['pv']['pvOrder'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";    
                
                $showArray['pv'][$key]['name'] = $row['name'];
                $showArray['pv'][$key]['pvTopic'] = $row['pvTopic'];
                $showArray['pv'][$key]['pvOrder'] = $row['pvOrder'];
                $showArray['pv'][$key]['orderPercentInfo'] = $orderPercentInfo;
                
                
            }
            
            $this->view->pvRows = $showArray['pv'];
            //uv
            $reUvArray = array();
            $reUvOtherArray = array();
            $reUvOtherArray['other']['name'] = '';
            $reUvOtherArray['other']['uvTopicPercent'] = 0;
            $reUvOtherArray['other']['uvTopic'] = 0;
            $reUvOtherArray['other']['uvOrder'] = 0;
            foreach ($reRows as $key => $row){
                if($row['uvTopicPercent']<1){
                   $reUvOtherArray['other']['name'] = '其他';
                   $reUvOtherArray['other']['uvTopic'] = $reUvOtherArray['other']['uvTopic'] + $row['uvTopic'];
                   $reUvOtherArray['other']['uvOrder'] = $reUvOtherArray['other']['uvOrder'] + $row['uvOrder'];
                } else {
                   $reUvArray[$row['pageName']]['name'] = $row['pageName'];
                   $reUvArray[$row['pageName']]['uvTopic'] = $row['uvTopic'];
                   $reUvArray[$row['pageName']]['uvOrder'] = $row['uvOrder'];
                }
                
            }
            if($reUvOtherArray['other']['uvTopic']>0){
                $reUvArray = array_merge($reUvArray,$reUvOtherArray);
            }
            
            
            $count['uv']['uvTopic']  = 0;
            $count['uv']['uvOrder'] = 0;
			$count['uv']['orderPercentInfo'] = 0;
            $showArray['uv'] = array();
            foreach($reUvArray as $key=>$row) {
                $count['uv']['uvTopic'] = $count['uv']['uvTopic']+$row['uvTopic'];
                $count['uv']['uvOrder'] = $count['uv']['uvOrder']+$row['uvOrder'];
                $count['uv']['orderPercentInfo'] = $count['uv']['uvTopic']>0 ? '100%' : '0%';
            }
            
            foreach($reUvArray as $key=>$row) {        
                //占比 提交订单
                $orderPercent = $count['uv']['uvOrder']>0 ? number_format($row['uvOrder']/$count['uv']['uvOrder'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";    
                
                $showArray['uv'][$key]['name'] = $row['name'];
                $showArray['uv'][$key]['uvTopic'] = $row['uvTopic'];
                $showArray['uv'][$key]['uvOrder'] = $row['uvOrder'];
                $showArray['uv'][$key]['orderPercentInfo'] = $orderPercentInfo;
                
                
            }
            
            $this->view->uvRows = $showArray['uv'];
            $this->view->countAll = $count;
            
            //导出Excel
            if ($vars['export']=='yes'){
                $exportArray = array();
                $exportNum =1;
                foreach ($showArray['pv'] as $row){
                    $exportNum++;
                    $exportArray['pv']['A'.$exportNum]= $row['name'];
                    $exportArray['pv']['B'.$exportNum]= $row['pvTopic'];
                    $exportArray['pv']['C'.$exportNum]= $row['pvOrder'];
                    $exportArray['pv']['D'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['pv']['A'.$exportNum]= '总计';
                $exportArray['pv']['B'.$exportNum]= $count['pv']['pvTopic'];
                $exportArray['pv']['C'.$exportNum]= $count['pv']['pvOrder'];
                $exportArray['pv']['D'.$exportNum]= $count['pv']['orderPercentInfo'];
                
                $exportNum =1;
                foreach ($showArray['uv'] as $row){
                    $exportNum++;
                    $exportArray['uv']['A'.$exportNum]= $row['name'];
                    $exportArray['uv']['B'.$exportNum]= $row['uvTopic'];
                    $exportArray['uv']['C'.$exportNum]= $row['uvOrder'];
                    $exportArray['uv']['D'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['uv']['A'.$exportNum]= '总计';
                $exportArray['uv']['B'.$exportNum]= $count['uv']['uvTopic'];
                $exportArray['uv']['C'.$exportNum]= $count['uv']['uvOrder'];
                $exportArray['uv']['D'.$exportNum]= $count['uv']['orderPercentInfo'];
                
                $table = array();
                $table[0]['tableName'] = '页面转化率-按专题(pv)';
                $table[0]['title'] = array('专题名称','专题浏览次数','提交订单数量','提交订单占比(%)');
                $table[0]['con'] = $exportArray['pv'];
                $table[1]['tableName'] = '页面转化率-按专题(uv)';
                $table[1]['title'] = array('专题名称','专题浏览人数','提交订单人数','提交订单占比(%)');
                $table[1]['con'] = $exportArray['uv'];
                $this->_model->excelExport($table,"[{$vars['startTime']}_{$vars['endTime']}]{$productCode}-topic-export");
            }
            
            
        } elseif ($vars['doType']==3){ //按操作系统
            $wheres[] = $this->_whereByClear2;
            $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
            $startappModel = new Application_Model_ActDayDataStartapp();
            $sql = "SELECT osName,sum(pvStart) as pv,sum(uvStart) as uv FROM `{$startappModel->getTableName()}` {$where} GROUP BY osName ORDER BY {$orderBy}";
    
            $startappRows = $startappModel ->getAdapter()->fetchAll($sql);
            
            
            //商品详情页
            $pagevisitModel = new Application_Model_ActDayDataPagevisit();
            $sql = "SELECT osName,sum(pv) as pv,sum(uv) as uv FROM `{$pagevisitModel->getTableName()}` {$where} AND pageId='1007' GROUP BY osName ORDER BY {$orderBy}";
            $productInfoRows = $pagevisitModel ->getAdapter()->fetchAll($sql);
            $reProductInfoRows = array();
            foreach ($productInfoRows as $key=>$row){
                $reProductInfoRows[$row['osName']]['pv'] = $row['pv'];
                $reProductInfoRows[$row['osName']]['uv'] = $row['uv'];
            }
            
            //结算中心
            $sql = "SELECT osName,sum(pv) as pv,sum(uv) as uv FROM `{$pagevisitModel->getTableName()}` {$where} AND pageId='1012' GROUP BY osName ORDER BY {$orderBy}";
            $toCountRows = $pagevisitModel ->getAdapter()->fetchAll($sql);
            $reToCountRows = array();
            foreach ($toCountRows as $key=>$row){
                $reToCountRows[$row['osName']]['pv'] = $row['pv'];
                $reToCountRows[$row['osName']]['uv'] = $row['uv'];
            }
            
            //加入购物车
            $sql = "SELECT osName,sum(pv) as pv,sum(uv) as uv FROM `{$this ->_model->getTableName()}` {$where} AND pageId='1003' GROUP BY osName ORDER BY {$orderBy}";
            $shoppingRows = $this ->_model ->getAdapter()->fetchAll($sql);
            $reShoppingRows = array();
            foreach ($shoppingRows as $key=>$row){
                $reShoppingRows[$row['osName']]['pv'] = $row['pv'];
                $reShoppingRows[$row['osName']]['uv'] = $row['uv'];
            }
            
            //提交订单
            $sql = "SELECT osName,sum(pv) as pv,sum(uv) as uv FROM `{$this ->_model->getTableName()}` {$where} AND pageId='1007' GROUP BY osName ORDER BY {$orderBy}";
            $orderRows = $this ->_model ->getAdapter()->fetchAll($sql);
            $reOrderRows = array();
            foreach ($orderRows as $key=>$row){
                $reOrderRows[$row['osName']]['pv'] = $row['pv'];
                $reOrderRows[$row['osName']]['uv'] = $row['uv'];
            }
            
            //合计
            $countStartApp = array();
            $countStartApp['pvStart'] = 0;
            $countStartApp['uvStart'] = 0;
            foreach($startappRows as $key=>$row) {
                $countStartApp['pvStart'] = $countStartApp['pvStart'] + $row['pv'];
                $countStartApp['uvStart'] = $countStartApp['uvStart'] + $row['uv'];
            }
            
            $reRows = array();
            foreach($startappRows as $key=>$row) {
                //启动所点比例 
                $reRows[$row['osName']]['pvStartPercent'] = $countStartApp['pvStart']>0 ? number_format($row['pv']/$countStartApp['pvStart'],3)*100 : 0;
                $reRows[$row['osName']]['uvStartPercent'] = $countStartApp['uvStart']>0 ? number_format($row['uv']/$countStartApp['uvStart'],3)*100 : 0;
                
                //启动次数
                $reRows[$row['osName']]['osName'] = $row['osName'];
                $reRows[$row['osName']]['pvStart'] = $row['pv'];
                $reRows[$row['osName']]['uvStart'] = $row['uv'];
                
                //商品详情页
                $reRows[$row['osName']]['pvProductInfo'] = 0;
                if(isset($reProductInfoRows[$row['osName']]['pv'])){
                    $reRows[$row['osName']]['pvProductInfo'] = $reProductInfoRows[$row['osName']]['pv'];
                }
                $reRows[$row['osName']]['uvProductInfo'] = 0;
                if(isset($reProductInfoRows[$row['osName']]['uv'])){
                    $reRows[$row['osName']]['uvProductInfo'] = $reProductInfoRows[$row['osName']]['uv'];
                }
                
                //结算中心
                $reRows[$row['osName']]['pvToCount'] = 0;
                if(isset($reToCountRows[$row['osName']]['pv'])){
                    $reRows[$row['osName']]['pvToCount'] = $reToCountRows[$row['osName']]['pv'];
                }
                $reRows[$row['osName']]['uvToCount'] = 0;
                if(isset($reToCountRows[$row['osName']]['uv'])){
                    $reRows[$row['osName']]['uvToCount'] = $reToCountRows[$row['osName']]['uv'];
                }
                
                
                //购物车
                $reRows[$row['osName']]['pvShopping'] = 0;
                if(isset($reShoppingRows[$row['osName']]['pv'])){
                    $reRows[$row['osName']]['pvShopping'] = $reShoppingRows[$row['osName']]['pv'];
                }
                $reRows[$row['osName']]['uvShopping'] = 0;
                if(isset($reShoppingRows[$row['osName']]['uv'])){
                    $reRows[$row['osName']]['uvShopping'] = $reShoppingRows[$row['osName']]['uv'];
                }
                
                //提交订单
                $reRows[$row['osName']]['pvOrder'] = 0;
                if(isset($reOrderRows[$row['osName']]['pv'])){
                    $reRows[$row['osName']]['pvOrder'] = $reOrderRows[$row['osName']]['pv'];
                }
                $reRows[$row['osName']]['uvOrder'] = 0;
                if(isset($reOrderRows[$row['osName']]['uv'])){
                    $reRows[$row['osName']]['uvOrder'] = $reOrderRows[$row['osName']]['uv'];
                }
                
                
            }
            
            //合计
            $count = array();
            $count['pv']['pvStart'] = 0;
			$count['pv']['pvStartPercent'] = 0;
            $count['pv']['pvProductInfo'] = 0;
            $count['pv']['pvShopping'] = 0;
            $count['pv']['shoppingPercentInfo'] = 0;
            $count['pv']['pvShoppingNum'] = 0;
            $count['pv']['shoppingNumPercentInfo'] = 0;
            $count['pv']['pvToCount'] = 0;
            $count['pv']['toCountPercentInfo'] = 0;
            $count['pv']['pvOrder'] = 0;
            $count['pv']['orderPercentInfo'] = 0;
            $showArray['pv'] = array();
            foreach($reRows as $key=>$row) {
                //转化率 加入购物车
                $shoppingPercent = $row['pvStart']>0 ? number_format($row['pvShopping']/$row['pvStart'],4)*100 : 0 ;
                $shoppingPercent = $shoppingPercent>100 ? 100 : $shoppingPercent ;
                $shoppingPercentInfo =  $shoppingPercent."%";
                
                //转化率 结算中心
                $toCountPercent = $row['pvStart']>0 ? number_format($row['pvToCount']/$row['pvStart'],4)*100 : 0 ;
                $toCountPercent = $toCountPercent>100 ? 100 : $toCountPercent ;
                $toCountPercentInfo =  $toCountPercent."%";
                
                //转化率 提交订单
                $orderPercent = $row['pvStart']>0 ? number_format($row['pvOrder']/$row['pvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                //合计
                $count['pv']['pvStart'] = $count['pv']['pvStart'] + $row['pvStart'];
                $count['pv']['pvStartPercent'] = $count['pv']['pvStart']>0 ? '100%' : '0%';
                $count['pv']['pvProductInfo'] = $count['pv']['pvProductInfo'] + $row['pvProductInfo'];
                $count['pv']['pvShopping'] = $count['pv']['pvShopping'] + $row['pvShopping'];
                $countShoppingPercentInfo = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvShopping']/$count['pv']['pvStart'],4)*100 : 0;
                $count['pv']['shoppingPercentInfo'] = $countShoppingPercentInfo.'%';
                $count['pv']['pvShoppingNum'] = $count['pv']['pvShoppingNum'] + $row['pvShopping'];
                $count['pv']['shoppingNumPercentInfo'] = $shoppingPercentInfo.'%';
                $count['pv']['pvToCount'] = $count['pv']['pvToCount'] + $row['pvToCount'];
                $countToCountPercentInfo = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvToCount']/$count['pv']['pvStart'],4)*100  : 0;;
                $count['pv']['toCountPercentInfo'] = $countToCountPercentInfo.'%';
                $count['pv']['pvOrder'] = $count['pv']['pvOrder'] + $row['pvOrder'];
                $countOrderPercentInfo = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvOrder']/$count['pv']['pvStart'],4)*100  : 0;
                $count['pv']['orderPercentInfo'] = $countOrderPercentInfo.'%';
                
                $showArray['pv'][$key]['osName'] = $row['osName'];
                $showArray['pv'][$key]['pvStart'] = $row['pvStart'];
                $showArray['pv'][$key]['pvStartPercent'] = $row['pvStartPercent'].'%';
                $showArray['pv'][$key]['pvProductInfo'] = $row['pvProductInfo'];
                $showArray['pv'][$key]['pvShopping'] =  $row['pvShopping'];
                $showArray['pv'][$key]['shoppingPercentInfo'] = $shoppingPercentInfo;
                $showArray['pv'][$key]['pvShoppingNum'] = $row['pvShopping'];
                $showArray['pv'][$key]['shoppingNumPercentInfo'] = $shoppingPercentInfo;
                $showArray['pv'][$key]['pvToCount'] = $row['pvToCount'];
                $showArray['pv'][$key]['toCountPercentInfo'] = $toCountPercentInfo;
                $showArray['pv'][$key]['pvOrder'] = $row['pvOrder'];
                $showArray['pv'][$key]['orderPercentInfo'] = $orderPercentInfo;
            }
            
            $count['uv']['uvStart'] = 0;
			$count['uv']['uvStartPercent'] = 0;
            $count['uv']['uvProductInfo'] = 0;
            $count['uv']['productInfoPercentInfo'] = 0;
            $count['uv']['uvShopping'] = 0;
            $count['uv']['shoppingPercentInfo'] = 0;
            $count['uv']['uvOrder'] = 0;
            $count['uv']['orderPercentInfo'] = 0;
            $showArray['uv'] = array();
            foreach($reRows as $key=>$row) {
                //转化率 商品详情
                $productInfoPercent = $row['uvStart']>0 ? number_format($row['uvProductInfo']/$row['uvStart'],4)*100 : 0 ;
                $productInfoPercent = $productInfoPercent>100 ? 100 : $productInfoPercent ;
                $productInfoPercentInfo =  $productInfoPercent."%";
                
                //转化率 加入购物车
                $shoppingPercent = $row['uvStart']>0 ? number_format($row['uvShopping']/$row['uvStart'],4)*100 : 0 ;
                $shoppingPercent = $shoppingPercent>100 ? 100 : $shoppingPercent ;
                $shoppingPercentInfo =  $shoppingPercent."%";
                
                //转化率 提交订单
                $orderPercent = $row['uvStart']>0 ? number_format($row['uvOrder']/$row['uvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                //合计
                $count['uv']['uvStart'] = $count['uv']['uvStart'] + $row['uvStart'];
                $count['uv']['uvStartPercent'] = $count['uv']['uvStart']>0 ? '100%' : '0%';
                $count['uv']['uvProductInfo'] = $count['uv']['uvProductInfo'] + $row['uvProductInfo'];
                $countProductInfoPercentInfo = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvProductInfo']/$count['uv']['uvStart'],4)*100 : 0;
                $count['uv']['productInfoPercentInfo'] = $countProductInfoPercentInfo.'%';
                $count['uv']['uvShopping'] = $count['uv']['uvShopping'] + $row['uvShopping'];
                $countShoppingPercentInfo = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvShopping']/$count['uv']['uvStart'],4)*100 : 0;
                $count['uv']['shoppingPercentInfo'] = $countShoppingPercentInfo.'%';
                $count['uv']['uvOrder'] = $count['uv']['uvOrder'] + $row['uvOrder'];
                $countOrderPercentInfo = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvOrder']/$count['uv']['uvStart'],4)*100  : 0;
                $count['uv']['orderPercentInfo'] = $countOrderPercentInfo.'%';
                
                
                $showArray['uv'][$key]['osName'] = $row['osName'];
                $showArray['uv'][$key]['uvStart'] = $row['uvStart'];
                $showArray['uv'][$key]['uvStartPercent'] = $row['uvStartPercent'].'%';
                $showArray['uv'][$key]['uvProductInfo'] = $row['uvProductInfo'];
                $showArray['uv'][$key]['productInfoPercentInfo'] = $productInfoPercentInfo;
                $showArray['uv'][$key]['uvShopping'] =  $row['uvShopping'];
                $showArray['uv'][$key]['shoppingPercentInfo'] = $shoppingPercentInfo;
                $showArray['uv'][$key]['uvOrder'] = $row['uvOrder'];
                $showArray['uv'][$key]['orderPercentInfo'] = $orderPercentInfo;
                
            }
            
            $this->view->pvRows = $showArray['pv'];
            $this->view->uvRows = $showArray['uv'];
            $this->view->countAll = $count;
            
            //检查是否有菜单访问权限
            $userLoginModel = Application_Model_UserLogin::getInstance();
            $currentUserRow = $userLoginModel->getLoginedRow();
            $menu = array('module'=>$this->_request->getModuleName(), 'controller'=>$this->_request->getControllerName(), 'action'=>'getdata-by-osname');
            $menuIsAccess = $userLoginModel->menuIsAccess($menu, $currentUserRow['id'], $userLoginModel->getUserCurrentRoleId(), $userLoginModel->getUserCurrentProductCode());
            $this->view->ajaxMenuIsAccess = $menuIsAccess;
            
            
            //导出Excel
            if ($vars['export']=='yes'){
                $exportArray = array();
                $exportNum =1;
                foreach ($showArray['pv'] as $row){
                    $exportNum++;
                    $exportArray['pv']['A'.$exportNum]= $row['osName'];
                    $exportArray['pv']['B'.$exportNum]= $row['pvStart'];
                    $exportArray['pv']['C'.$exportNum]= $row['pvStartPercent'];
                    $exportArray['pv']['D'.$exportNum]= $row['pvProductInfo'];
                    $exportArray['pv']['E'.$exportNum]= $row['pvShopping'];
                    $exportArray['pv']['F'.$exportNum]= $row['shoppingPercentInfo'];
                    $exportArray['pv']['G'.$exportNum]= $row['pvShoppingNum'];
                    $exportArray['pv']['H'.$exportNum]= $row['shoppingNumPercentInfo'];
                    $exportArray['pv']['I'.$exportNum]= $row['pvToCount'];
                    $exportArray['pv']['J'.$exportNum]= $row['toCountPercentInfo'];
                    $exportArray['pv']['K'.$exportNum]= $row['pvOrder'];
                    $exportArray['pv']['L'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['pv']['A'.$exportNum]= '总计';
                $exportArray['pv']['B'.$exportNum]= $count['pv']['pvStart'];
                $exportArray['pv']['C'.$exportNum]= $count['pv']['pvStartPercent'];
                $exportArray['pv']['D'.$exportNum]= $count['pv']['pvProductInfo'];
                $exportArray['pv']['E'.$exportNum]= $count['pv']['pvShopping'];
                $exportArray['pv']['F'.$exportNum]= $count['pv']['shoppingPercentInfo'];
                $exportArray['pv']['G'.$exportNum]= $count['pv']['pvShoppingNum'];
                $exportArray['pv']['H'.$exportNum]= $count['pv']['shoppingNumPercentInfo'];
                $exportArray['pv']['I'.$exportNum]= $count['pv']['pvToCount'];
                $exportArray['pv']['J'.$exportNum]= $count['pv']['toCountPercentInfo'];
                $exportArray['pv']['K'.$exportNum]= $count['pv']['pvOrder'];
                $exportArray['pv']['L'.$exportNum]= $count['pv']['orderPercentInfo'];
                
                $exportNum =1;
                foreach ($showArray['uv'] as $row){
                    $exportNum++;
                    $exportArray['uv']['A'.$exportNum]= $row['osName'];
                    $exportArray['uv']['B'.$exportNum]= $row['uvStart'];
                    $exportArray['uv']['C'.$exportNum]= $row['uvStartPercent'];
                    $exportArray['uv']['D'.$exportNum]= $row['uvProductInfo'];
                    $exportArray['uv']['E'.$exportNum]= $row['productInfoPercentInfo'];
                    $exportArray['uv']['F'.$exportNum]= $row['uvShopping'];
                    $exportArray['uv']['G'.$exportNum]= $row['shoppingPercentInfo'];
                    $exportArray['uv']['H'.$exportNum]= $row['uvOrder'];
                    $exportArray['uv']['I'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['uv']['A'.$exportNum]= '总计';
                $exportArray['uv']['B'.$exportNum]= $count['uv']['uvStart'];
                $exportArray['uv']['C'.$exportNum]= $count['uv']['uvStartPercent'];
                $exportArray['uv']['D'.$exportNum]= $count['uv']['uvProductInfo'];
                $exportArray['uv']['E'.$exportNum]= $count['uv']['productInfoPercentInfo'];
                $exportArray['uv']['F'.$exportNum]= $count['uv']['uvShopping'];
                $exportArray['uv']['G'.$exportNum]= $count['uv']['shoppingPercentInfo'];
                $exportArray['uv']['H'.$exportNum]= $count['uv']['uvOrder'];
                $exportArray['uv']['I'.$exportNum]= $count['uv']['orderPercentInfo'];
                
                $table = array();
                $table[0]['tableName'] = '页面转化率-按操作系统(pv)';
                $table[0]['title'] = array('操作系统','启动次数','启动次数占比(%)','商品详情页浏览次数','加入购物车次数','加入购物车转化率','加入购物车商品数量','加入购物车商品转化率','进入订单页面次数','进入订单页面转化率','提交订单数量','提交订单转化率');
                $table[0]['con'] = $exportArray['pv'];
                $table[1]['tableName'] = '页面转化率-按操作系统(uv)';
                $table[1]['title'] = array('操作系统','启动人数','启动人数占比(%)','进入商品详情页人数','进入商品详情页转化率','加入购物车人数','加入购物车转化率','提交订单人数','提交订单转化率');
                $table[1]['con'] = $exportArray['uv'];
                $this->_model->excelExport($table,"[{$vars['startTime']}_{$vars['endTime']}]{$productCode}-osName-export");
            }
            
            
        } elseif ($vars['doType']==4){ //按地域
            $wheres[] = $this->_whereByClear2;
            $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
            
            $startappareaModel = new Application_Model_ActDayDataStartapparea();
            $sql = "SELECT province AS name,sum(pvStart) as pv,sum(uvStart) as uv FROM `{$startappareaModel->getTableName()}` {$where} GROUP BY name  ORDER BY {$orderBy}";
            $startappRows = $startappareaModel ->getAdapter()->fetchAll($sql);
            
            //启动 合计
            $countStartApp = array();
            $countStartApp['pvStart'] = 0;
            $countStartApp['uvStart'] = 0;
            foreach($startappRows as $key=>$row) {
                $countStartApp['pvStart'] = $countStartApp['pvStart'] + $row['pv'];
                $countStartApp['uvStart'] = $countStartApp['uvStart'] + $row['uv'];
            }
            //启动
            $reStartappRows = array();
            $startappProvince = array();
            foreach ($startappRows as $key=>$row){
                $row['name'] = trim($row['name']);
                if ($row['name']==''|| $row['name']=='其他'){
                    $row['name'] = '国外';
                }
                $reStartappRows[$row['name']]['pvStart'] = isset($reStartappRows[$row['name']]['pvStart']) ? $reStartappRows[$row['name']]['pvStart']+$row['pv'] : $row['pv'];
                $reStartappRows[$row['name']]['uvStart'] = isset($reStartappRows[$row['name']]['uvStart']) ? $reStartappRows[$row['name']]['uvStart']+$row['uv'] : $row['uv'];
                //启动所点比例 
                $reStartappRows[$row['name']]['pvStartPercent'] = $countStartApp['pvStart']>0 ? number_format($row['pv']/$countStartApp['pvStart'],4)*100 : 0;
                $reStartappRows[$row['name']]['uvStartPercent'] = $countStartApp['uvStart']>0 ? number_format($row['uv']/$countStartApp['uvStart'],4)*100 : 0;
                //启动所在的省列表
                $startappProvinceArray[] = $row['name'];
            }
            
            //商品详情页
            $pagevisitareaModel = new Application_Model_ActDayDataPagevisitarea();
            $sql = "SELECT province AS name,sum(pv) as pv,sum(uv) as uv FROM `{$pagevisitareaModel->getTableName()}` {$where} AND pageId='1007' GROUP BY name ORDER BY {$orderBy}";
            //echo $sql;
            $productInfoRows = $pagevisitareaModel ->getAdapter()->fetchAll($sql);
            $reProductInfoRows = array();
            $productInfoProvinceArray = array();
            foreach ($productInfoRows as $key=>$row){
                $row['name'] = trim($row['name']);
                if ($row['name']==''|| $row['name']=='其他'){
                    $row['name'] = '国外';
                }
                $reProductInfoRows[$row['name']]['pv'] = isset($reProductInfoRows[$row['name']]['pv']) ? $reProductInfoRows[$row['name']]['pv']+$row['pv'] : $row['pv'];
                $reProductInfoRows[$row['name']]['uv'] = isset($reProductInfoRows[$row['name']]['uv']) ? $reProductInfoRows[$row['name']]['uv']+$row['uv'] : $row['uv'];
                //商品详情所在省列表
                $productInfoProvinceArray[] = $row['name'];
            }
            
            //结算中心
            $sql = "SELECT province AS name,sum(pv) as pv,sum(uv) as uv FROM `{$pagevisitareaModel->getTableName()}` {$where} AND pageId='1012' GROUP BY name ORDER BY {$orderBy}";
            $toCountRows = $pagevisitareaModel ->getAdapter()->fetchAll($sql);
            $reToCountRows = array();
            foreach ($toCountRows as $key=>$row){
                $row['name'] = trim($row['name']);
                if ($row['name']==''|| $row['name']=='其他'){
                    $row['name'] = '国外';
                }
                $reToCountRows[$row['name']]['pv'] = isset($reToCountRows[$row['name']]['pv']) ? $reToCountRows[$row['name']]['pv']+$row['pv'] : $row['pv'];
                $reToCountRows[$row['name']]['uv'] = isset($reToCountRows[$row['name']]['uv']) ? $reToCountRows[$row['name']]['uv']+$row['uv'] : $row['uv'];
            }
            
            
            $conversionareaModel = new Application_Model_ActDayDataConversionarea();
            //加入购物车
            $sql = "SELECT province as name,sum(pv) as pv,sum(uv) as uv FROM `{$conversionareaModel->getTableName()}` {$where} AND pageId='1003' GROUP BY name ORDER BY {$orderBy}";
            $shoppingRows = $conversionareaModel ->getAdapter()->fetchAll($sql);
            $reShoppingRows = array();
            foreach ($shoppingRows as $key=>$row){
                $row['name'] = trim($row['name']);
                if ($row['name']==''|| $row['name']=='其他'){
                    $row['name'] = '国外';
                }
                $reShoppingRows[$row['name']]['pv'] = isset($reShoppingRows[$row['name']]['pv']) ? $reShoppingRows[$row['name']]['pv']+$row['pv'] : $row['pv'];
                $reShoppingRows[$row['name']]['uv'] = isset($reShoppingRows[$row['name']]['uv']) ? $reShoppingRows[$row['name']]['uv']+$row['uv'] : $row['uv'];
            }
            
            //提交订单
            $sql = "SELECT province as name,sum(pv) as pv,sum(uv) as uv FROM `{$conversionareaModel->getTableName()}` {$where} AND pageId='1007' GROUP BY name ORDER BY {$orderBy}";
            $orderRows = $conversionareaModel ->getAdapter()->fetchAll($sql);
            $reOrderRows = array();
            foreach ($orderRows as $key=>$row){
                $row['name'] = trim($row['name']);
                if ($row['name']==''|| $row['name']=='其他'){
                    $row['name'] = '国外';
                }
                $reOrderRows[$row['name']]['pv'] = isset($reOrderRows[$row['name']]['pv'])? $reOrderRows[$row['name']]['pv']+$row['pv'] : $row['pv'];
                $reOrderRows[$row['name']]['uv'] = isset($reOrderRows[$row['name']]['uv']) ? $reOrderRows[$row['name']]['uv']+$row['uv'] : $row['uv'];
            }
            
            //重定 省数组
            $countArray = array();
            $countArray = array_merge($startappProvinceArray,$productInfoProvinceArray);//count($startappRows)>count($productInfoRows) ? $startappRows : $productInfoRows ;
            $countArray = array_unique($countArray);
            
            
            
            $reRows = array();
            foreach($countArray as $key=>$element) {
                
                //启动所点比例 
                $reRows[$element]['pvStartPercent'] = 0;
                if (isset($reStartappRows[$element]['pvStartPercent'])){
                    $reRows[$element]['pvStartPercent'] = $reStartappRows[$element]['pvStartPercent'];
                }
                $reRows[$element]['uvStartPercent'] = 0;
                if (isset($reStartappRows[$element]['uvStartPercent'])){
                    $reRows[$element]['uvStartPercent'] = $reStartappRows[$element]['uvStartPercent'];
                }
                
                //启动次数
                $reRows[$element]['name'] = $element;
                $reRows[$element]['pvStart'] = 0;
                if(isset($reStartappRows[$element]['pvStart'])){
                    $reRows[$element]['pvStart'] = $reStartappRows[$element]['pvStart'];
                }
                $reRows[$element]['uvStart'] = 0;
                if(isset($reStartappRows[$element]['uvStart'])){
                    $reRows[$element]['uvStart'] = $reStartappRows[$element]['uvStart'];
                }
                
                
                //商品详情页
                $reRows[$element]['pvProductInfo'] = 0;
                if(isset($reProductInfoRows[$element]['pv'])){
                    $reRows[$element]['pvProductInfo'] = $reProductInfoRows[$element]['pv'];
                }
                $reRows[$element]['uvProductInfo'] = 0;
                if(isset($reProductInfoRows[$element]['uv'])){
                    $reRows[$element]['uvProductInfo'] = $reProductInfoRows[$element]['uv'];
                }
                
                
                //结算中心
                $reRows[$element]['pvToCount'] = 0;
                if(isset($reToCountRows[$element]['pv'])){
                    $reRows[$element]['pvToCount'] = $reToCountRows[$element]['pv'];
                }
                $reRows[$element]['uvToCount'] = 0;
                if(isset($reToCountRows[$element]['uv'])){
                    $reRows[$element]['uvToCount'] = $reToCountRows[$element]['uv'];
                }
                
                
                
                //购物车
                $reRows[$element]['pvShopping'] = 0;
                if(isset($reShoppingRows[$element]['pv'])){
                    $reRows[$element]['pvShopping'] = $reShoppingRows[$element]['pv'];
                }
                $reRows[$element]['uvShopping'] = 0;
                if(isset($reShoppingRows[$element]['uv'])){
                    $reRows[$element]['uvShopping'] = $reShoppingRows[$element]['uv'];
                }
                
                //提交订单
                $reRows[$element]['pvOrder'] = 0;
                if(isset($reOrderRows[$element]['pv'])){
                    $reRows[$element]['pvOrder'] = $reOrderRows[$element]['pv'];
                }
                $reRows[$element]['uvOrder'] = 0;
                if(isset($reOrderRows[$element]['uv'])){
                    $reRows[$element]['uvOrder'] = $reOrderRows[$element]['uv'];
                }
                
            }
            
            
            //合计
            $count = array();
            $count['pv']['pvStart'] = 0;
			$count['pv']['pvStartPercent'] = 0;
            $count['pv']['pvProductInfo'] = 0;
            $count['pv']['pvShopping'] = 0;
            $count['pv']['shoppingPercentInfo'] = 0;
            $count['pv']['pvShoppingNum'] = 0;
            $count['pv']['shoppingNumPercentInfo'] = 0;
            $count['pv']['pvToCount'] = 0;
            $count['pv']['toCountPercentInfo'] = 0;
            $count['pv']['pvOrder'] = 0;
            $count['pv']['orderPercentInfo'] = 0;
            $showArray['pv'] = array();
            foreach($reRows as $key=>$row) {
                //转化率 加入购物车
                $shoppingPercent = $row['pvStart']>0 ? number_format($row['pvShopping']/$row['pvStart'],4)*100 : 0 ;
                $shoppingPercent = $shoppingPercent>100 ? 100 : $shoppingPercent ;
                $shoppingPercentInfo =  $shoppingPercent."%";
                
                //转化率 结算中心
                $toCountPercent = $row['pvStart']>0 ? number_format($row['pvToCount']/$row['pvStart'],4)*100 : 0 ;
                $toCountPercent = $toCountPercent>100 ? 100 : $toCountPercent ;
                $toCountPercentInfo =  $toCountPercent."%";
                
                //转化率 提交订单
                $orderPercent = $row['pvStart']>0 ? number_format($row['pvOrder']/$row['pvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                
                //合计
                $count['pv']['pvStart'] = $count['pv']['pvStart'] + $row['pvStart'];
                $count['pv']['pvStartPercent'] = $count['pv']['pvStart']>0 ? '100%' : '0%';
                $count['pv']['pvProductInfo'] = $count['pv']['pvProductInfo'] + $row['pvProductInfo'];
                $count['pv']['pvShopping'] = $count['pv']['pvShopping'] + $row['pvShopping'];
                $countShoppingPercentInfo = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvShopping']/$count['pv']['pvStart'],4)*100 : 0;
                $count['pv']['shoppingPercentInfo'] = $countShoppingPercentInfo.'%';
                $count['pv']['pvShoppingNum'] = $count['pv']['pvShoppingNum'] + $row['pvShopping'];
                $count['pv']['shoppingNumPercentInfo'] = $shoppingPercentInfo.'%';
                $count['pv']['pvToCount'] = $count['pv']['pvToCount'] + $row['pvToCount'];
                $countToCountPercentInfo = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvToCount']/$count['pv']['pvStart'],4)*100  : 0;;
                $count['pv']['toCountPercentInfo'] = $countToCountPercentInfo.'%';
                $count['pv']['pvOrder'] = $count['pv']['pvOrder'] + $row['pvOrder'];
                $countOrderPercentInfo = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvOrder']/$count['pv']['pvStart'],4)*100  : 0;
                $count['pv']['orderPercentInfo'] = $countOrderPercentInfo.'%';
                
                
                $showArray['pv'][$key]['name'] = $row['name'];
                $showArray['pv'][$key]['pvStart'] = $row['pvStart'];
                $showArray['pv'][$key]['pvStartPercent'] = $row['pvStartPercent'].'%';
                $showArray['pv'][$key]['pvProductInfo'] = $row['pvProductInfo'];
                $showArray['pv'][$key]['pvShopping'] =  $row['pvShopping'];
                $showArray['pv'][$key]['shoppingPercentInfo'] = $shoppingPercentInfo;
                $showArray['pv'][$key]['pvShoppingNum'] = $row['pvShopping'];
                $showArray['pv'][$key]['shoppingNumPercentInfo'] = $shoppingPercentInfo;
                $showArray['pv'][$key]['pvToCount'] = $row['pvToCount'];
                $showArray['pv'][$key]['toCountPercentInfo'] = $toCountPercentInfo;
                $showArray['pv'][$key]['pvOrder'] = $row['pvOrder'];
                $showArray['pv'][$key]['orderPercentInfo'] = $orderPercentInfo;
                
            }
            
            
            $count['uv']['uvStart'] = 0;
			$count['uv']['uvStartPercent'] = 0;
            $count['uv']['uvProductInfo'] = 0;
            $count['uv']['productInfoPercentInfo'] = 0;
            $count['uv']['uvShopping'] = 0;
            $count['uv']['shoppingPercentInfo'] = 0;
            $count['uv']['uvOrder'] = 0;
            $count['uv']['orderPercentInfo'] = 0;
            $showArray['uv'] = array();
            foreach($reRows as $key=>$row) {
                //转化率 商品详情
                $productInfoPercent = $row['uvStart']>0 ? number_format($row['uvProductInfo']/$row['uvStart'],4)*100 : 0 ;
                $productInfoPercent = $productInfoPercent>100 ? 100 : $productInfoPercent ;
                $productInfoPercentInfo =  $productInfoPercent."%";
                
                //转化率 加入购物车
                $shoppingPercent = $row['uvStart']>0 ? number_format($row['uvShopping']/$row['uvStart'],4)*100 : 0 ;
                $shoppingPercent = $shoppingPercent>100 ? 100 : $shoppingPercent ;
                $shoppingPercentInfo =  $shoppingPercent."%";
                
                //转化率 提交订单
                $orderPercent = $row['uvStart']>0 ? number_format($row['uvOrder']/$row['uvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                //合计
                $count['uv']['uvStart'] = $count['uv']['uvStart'] + $row['uvStart'];
                $count['uv']['uvStartPercent'] = $count['uv']['uvStart']>0 ? '100%' : '0%';
                $count['uv']['uvProductInfo'] = $count['uv']['uvProductInfo'] + $row['uvProductInfo'];
                $countProductInfoPercentInfo = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvProductInfo']/$count['uv']['uvStart'],4)*100 : 0;
                $count['uv']['productInfoPercentInfo'] = $countProductInfoPercentInfo.'%';
                $count['uv']['uvShopping'] = $count['uv']['uvShopping'] + $row['uvShopping'];
                $countShoppingPercentInfo = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvShopping']/$count['uv']['uvStart'],4)*100 : 0;
                $count['uv']['shoppingPercentInfo'] = $countShoppingPercentInfo.'%';
                $count['uv']['uvOrder'] = $count['uv']['uvOrder'] + $row['uvOrder'];
                $countOrderPercentInfo = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvOrder']/$count['uv']['uvStart'],4)*100  : 0;
                $count['uv']['orderPercentInfo'] = $countOrderPercentInfo.'%';
                
                
                $showArray['uv'][$key]['name'] = $row['name'];
                $showArray['uv'][$key]['uvStart'] = $row['uvStart'];
                $showArray['uv'][$key]['uvStartPercent'] = $row['uvStartPercent'].'%';
                $showArray['uv'][$key]['uvProductInfo'] = $row['uvProductInfo'];
                $showArray['uv'][$key]['productInfoPercentInfo'] = $productInfoPercentInfo;
                $showArray['uv'][$key]['uvShopping'] =  $row['uvShopping'];
                $showArray['uv'][$key]['shoppingPercentInfo'] = $shoppingPercentInfo;
                $showArray['uv'][$key]['uvOrder'] = $row['uvOrder'];
                $showArray['uv'][$key]['orderPercentInfo'] = $orderPercentInfo;
                
            }
            
            $this->view->pvRows = $showArray['pv'];
            $this->view->uvRows = $showArray['uv'];
            $this->view->countAll = $count;
            
            
            //导出Excel
            if ($vars['export']=='yes'){
                $exportArray = array();
                $exportNum =1;
                foreach ($showArray['pv'] as $row){
                    $exportNum++;
                    $exportArray['pv']['A'.$exportNum]= $row['name'];
                    $exportArray['pv']['B'.$exportNum]= $row['pvStart'];
                    $exportArray['pv']['C'.$exportNum]= $row['pvStartPercent'];
                    $exportArray['pv']['D'.$exportNum]= $row['pvProductInfo'];
                    $exportArray['pv']['E'.$exportNum]= $row['pvShopping'];
                    $exportArray['pv']['F'.$exportNum]= $row['shoppingPercentInfo'];
                    $exportArray['pv']['G'.$exportNum]= $row['pvShoppingNum'];
                    $exportArray['pv']['H'.$exportNum]= $row['shoppingNumPercentInfo'];
                    $exportArray['pv']['I'.$exportNum]= $row['pvToCount'];
                    $exportArray['pv']['J'.$exportNum]= $row['toCountPercentInfo'];
                    $exportArray['pv']['K'.$exportNum]= $row['pvOrder'];
                    $exportArray['pv']['L'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['pv']['A'.$exportNum]= '总计';
                $exportArray['pv']['B'.$exportNum]= $count['pv']['pvStart'];
                $exportArray['pv']['C'.$exportNum]= $count['pv']['pvStartPercent'];
                $exportArray['pv']['D'.$exportNum]= $count['pv']['pvProductInfo'];
                $exportArray['pv']['E'.$exportNum]= $count['pv']['pvShopping'];
                $exportArray['pv']['F'.$exportNum]= $count['pv']['shoppingPercentInfo'];
                $exportArray['pv']['G'.$exportNum]= $count['pv']['pvShoppingNum'];
                $exportArray['pv']['H'.$exportNum]= $count['pv']['shoppingNumPercentInfo'];
                $exportArray['pv']['I'.$exportNum]= $count['pv']['pvToCount'];
                $exportArray['pv']['J'.$exportNum]= $count['pv']['toCountPercentInfo'];
                $exportArray['pv']['K'.$exportNum]= $count['pv']['pvOrder'];
                $exportArray['pv']['L'.$exportNum]= $count['pv']['orderPercentInfo'];
                
                $exportNum =1;
                foreach ($showArray['uv'] as $row){
                    $exportNum++;
                    $exportArray['uv']['A'.$exportNum]= $row['name'];
                    $exportArray['uv']['B'.$exportNum]= $row['uvStart'];
                    $exportArray['uv']['C'.$exportNum]= $row['uvStartPercent'];
                    $exportArray['uv']['D'.$exportNum]= $row['uvProductInfo'];
                    $exportArray['uv']['E'.$exportNum]= $row['productInfoPercentInfo'];
                    $exportArray['uv']['F'.$exportNum]= $row['uvShopping'];
                    $exportArray['uv']['G'.$exportNum]= $row['shoppingPercentInfo'];
                    $exportArray['uv']['H'.$exportNum]= $row['uvOrder'];
                    $exportArray['uv']['I'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['uv']['A'.$exportNum]= '总计';
                $exportArray['uv']['B'.$exportNum]= $count['uv']['uvStart'];
                $exportArray['uv']['C'.$exportNum]= $count['uv']['uvStartPercent'];
                $exportArray['uv']['D'.$exportNum]= $count['uv']['uvProductInfo'];
                $exportArray['uv']['E'.$exportNum]= $count['uv']['productInfoPercentInfo'];
                $exportArray['uv']['F'.$exportNum]= $count['uv']['uvShopping'];
                $exportArray['uv']['G'.$exportNum]= $count['uv']['shoppingPercentInfo'];
                $exportArray['uv']['H'.$exportNum]= $count['uv']['uvOrder'];
                $exportArray['uv']['I'.$exportNum]= $count['uv']['orderPercentInfo'];
                
                $table = array();
                $table[0]['tableName'] = '页面转化率-按地域(pv)';
                $table[0]['title'] = array('地域名称','启动次数','启动次数占比(%)','商品详情页浏览次数','加入购物车次数','加入购物车转化率','加入购物车商品数量','加入购物车商品转化率','进入订单页面次数','进入订单页面转化率','提交订单数量','提交订单转化率');
                $table[0]['con'] = $exportArray['pv'];
                $table[1]['tableName'] = '页面转化率-按地域(uv)';
                $table[1]['title'] = array('地域名称','启动人数','启动人数占比(%)','进入商品详情页人数','进入商品详情页转化率','加入购物车人数','加入购物车转化率','提交订单人数','提交订单转化率');
                $table[1]['con'] = $exportArray['uv'];
                $this->_model->excelExport($table,"[{$vars['startTime']}_{$vars['endTime']}]{$productCode}-province-export");
            }
            
            
        } else {
            exit("未法操作");
        }
        $this->view->title = '页面转化率';
        $this->view->vars = $vars;
        
        //说明：
        $this->view->productCode = $productCode;
        
        
        
    }
    

    /**
     * 统计所有
     * 
     * @return void
     */
    public function countAction()
    {

        
        //设置URL模板以及条件
        $urls = array();
        $vars = array();
        $wheres = array();
        $vars['dateType']  = trim($this->_request->get('dateType')) ? trim($this->_request->get('dateType')) : 1;
        $vars['doType']    = trim($this->_request->get('doType')) ? trim($this->_request->get('doType')) : 1;
        $vars['startTime'] = trim($this->_request->get('startTime'));
        $vars['endTime']   = trim($this->_request->get('endTime'));
        $vars['export']   = trim($this->_request->get('export'))!='' ? trim($this->_request->get('export')) :'no';
        
        if ($vars['dateType']==1){
            $vars['startTime'] = date('Y-m-d',strtotime("-1 day"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==2){
            $vars['startTime'] = date('Y-m-d',strtotime("-8 day"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==3){
            $vars['startTime'] = date('Y-m-d',strtotime("-31 day"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==4){
            $vars['startTime'] = date('Y-m-d',strtotime("-3 months"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==5){
            $vars['startTime'] = '';
            $vars['endTime']   = '';
        }
        
        $urls = $vars;
        $productCode = Application_Model_UserLogin::getInstance()->getUserCurrentProductCode();
        $wheres[] = "`productCode` = '{$productCode}'";
        
        if ($vars['startTime'] != '') {
            $wheres[] = "`date` >= '{$vars['startTime']}' ";
        }
        if ($vars['endTime'] != '') {
            $wheres[] = "`date` <= '{$vars['endTime']}' ";
        }
        
        
        $orderBy = "`pv` DESC";
        if ($vars['doType']==1){ //按渠道
            $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
            
            //--启动----start---------------------
            $dayDataModel = new Application_Model_DayData();
            $sql = "SELECT code,name,sum(bootNum) as pv,sum(bootClientNum) as uv FROM `{$dayDataModel->getTableName()}` AS a LEFT JOIN (SELECT  mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId` FROM `mob_source` AS ms INNER JOIN `mob_member` AS mm ON  ms.memberCode=mm.code   WHERE  ms.productCode='{$productCode}' Group By mm.code,mm.name,ms.`sourceId`,ms.`sourceSubId`) AS b ON a.sourceId = b.sourceId AND a.sourceSubId=b.sourceSubId  {$where} GROUP BY code,name  ORDER BY {$orderBy}";
            $startappRows = $dayDataModel ->getAdapter()->fetchAll($sql);
            //--启动----end---------------------
            

            //提交订单
            $sourceModel = new Application_Model_Source();
            $sql = "SELECT `code`,MAX(`name`) AS name,SUM(num) AS pv,SUM(uv) AS uv FROM (
                        SELECT a.*,b.name,b.code FROM 
                        (
                            SELECT productcode,sourceid,sourceSubId,SUM(okOrderNum) AS num,SUM(okOrderClientNum) AS uv  FROM " . $dayDataModel->getTableName() . " 
                            " . $where . "
                            GROUP BY productcode,sourceid,sourceSubId
                            
                        ) AS a
                        LEFT JOIN
                        (
                            SELECT `name`,`code`,productcode,sourceid,sourcesubid FROM " . $sourceModel->getTableName() . " LEFT JOIN `mob_member` ON mob_source.`memberCode`=`mob_member`.`code` 
                            WHERE productcode='" . $productCode . "'
                        ) AS b 
                        ON a.productcode=b.productcode AND a.sourceid=b.sourceid 
                        AND a.sourcesubid=b.sourcesubid
                    )aaa GROUP BY `code` ";
            $orderRows = $dayDataModel ->getAdapter()->fetchAll($sql);
            $reOrderRows = array();
            foreach ($orderRows as $key=>$row){
                $reOrderRows[$row['code']]['pv'] = $row['pv'];
                $reOrderRows[$row['code']]['uv'] = $row['uv'];
            }
            
            //合计
            $countStartApp = array();
            $countStartApp['pvStart'] = 0;
            $countStartApp['uvStart'] = 0;
            foreach($startappRows as $key=>$row) {
                $countStartApp['pvStart'] = $countStartApp['pvStart'] + $row['pv'];
                $countStartApp['uvStart'] = $countStartApp['uvStart'] + $row['uv'];
            }
            
            $reRows = array();
            foreach($startappRows as $key=>$row) {
                
                //启动所点比例 
                $reRows[$row['code']]['pvStartPercent'] = $countStartApp['pvStart']>0 ? number_format($row['pv']/$countStartApp['pvStart'],4)*100 : 0;
                $reRows[$row['code']]['uvStartPercent'] = $countStartApp['uvStart']>0 ? number_format($row['uv']/$countStartApp['uvStart'],4)*100 : 0;
                
                //启动次数
                $reRows[$row['code']]['code'] = $row['code'];
                $reRows[$row['code']]['name'] = $row['name'];
                $reRows[$row['code']]['pvStart'] = $row['pv'];
                $reRows[$row['code']]['uvStart'] = $row['uv'];
                
                
                //提交订单
                $reRows[$row['code']]['pvOrder'] = 0;
                if(isset($reOrderRows[$row['code']]['pv'])){
                    $reRows[$row['code']]['pvOrder'] = $reOrderRows[$row['code']]['pv'];
                }
                $reRows[$row['code']]['uvOrder'] = 0;
                if(isset($reOrderRows[$row['code']]['uv'])){
                    $reRows[$row['code']]['uvOrder'] = $reOrderRows[$row['code']]['uv'];
                }
                
            }
            
            
            //重组
            //pv
            $rePvArray = array();
            $rePvOtherArray = array();
            $rePvOtherArray['other']['code'] = '';
            $rePvOtherArray['other']['name'] = '';
            $rePvOtherArray['other']['pvStartPercent'] = 0;
            $rePvOtherArray['other']['pvStart'] = 0;
            $rePvOtherArray['other']['pvOrder'] = 0;
            $pvOtherCodeArray = array();
            foreach ($reRows as $key => $row){
                if($row['pvStartPercent']<0){
                   $rePvOtherArray['other']['code'] = 'other';
                   $rePvOtherArray['other']['name'] = '其他';
                   $rePvOtherArray['other']['pvStartPercent'] = $rePvOtherArray['other']['pvStartPercent'] + $row['pvStartPercent'];
                   $rePvOtherArray['other']['pvStart'] = $rePvOtherArray['other']['pvStart'] + $row['pvStart'];
                   $rePvOtherArray['other']['pvOrder'] = $rePvOtherArray['other']['pvOrder'] + $row['pvOrder'];
                   $pvOtherCodeArray[] = "\'{$row['code']}\'";
                } else {
                   $rePvArray[$row['code']]['code'] = $row['code'];
                   $rePvArray[$row['code']]['name'] = $row['name'];
                   $rePvArray[$row['code']]['pvStartPercent'] =  $row['pvStartPercent'];
                   $rePvArray[$row['code']]['pvStart'] =  $row['pvStart'];
                   $rePvArray[$row['code']]['pvOrder'] = $row['pvOrder'];
                }
            }
            if($rePvOtherArray['other']['pvStart']>0){
                $rePvArray = array_merge($rePvArray,$rePvOtherArray);
            }
            $pvOtherCodeStr = count($pvOtherCodeArray)>0 ? implode(',',$pvOtherCodeArray) : '';
            $this->view->pvOtherCodeStr = $pvOtherCodeStr;
            
            //合计
            $count = array();
            $count['pv']['pvStart'] = 0;
            $count['pv']['pvOrder'] = 0;
			$count['pv']['pvStartPercent'] = 0;
			$count['pv']['orderPercent'] = 0;
            $count['pv']['orderPercentInfo'] = 0;
            $count['pv']['num'] = 0;
            $pvShowArray = array();
            foreach($rePvArray as $key=>$row) {
                //转化率 提交订单
                $orderPercent = $row['pvStart']>0 ? number_format($row['pvOrder']/$row['pvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                //合计
                $count['pv']['pvStart'] = $count['pv']['pvStart'] + $row['pvStart'];
                $count['pv']['pvOrder'] = $count['pv']['pvOrder'] + $row['pvOrder'];
                $count['pv']['pvStartPercent'] = $count['pv']['pvStart']>0 ? '100%' : '0%';
                $orderPercent = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvOrder']/$count['pv']['pvStart'],4)*100 : 0;
                $count['pv']['orderPercent'] = $orderPercent.'%';
                $count['pv']['orderPercentInfo'] = $count['pv']['orderPercentInfo'] + $orderPercent;
                $count['pv']['num'] = $count['pv']['num']+1;
                
                $pvShowArray[$key]['code'] = $row['code'];
                $pvShowArray[$key]['name'] = $row['name'];
                $pvShowArray[$key]['pvStart'] = $row['pvStart'];
                $pvShowArray[$key]['pvStartPercent'] = $row['pvStartPercent'].'%';
                $pvShowArray[$key]['pvOrder'] = $row['pvOrder'];
                $pvShowArray[$key]['orderPercentInfo'] = $orderPercentInfo;
            }
            
            $this->view->pvRows = $pvShowArray;
            
            //uv
            $reUvArray = array();
            $reUvOtherArray = array();
            $reUvOtherArray['other']['code'] = '';
            $reUvOtherArray['other']['name'] = '';
            $reUvOtherArray['other']['uvStartPercent'] = 0;
            $reUvOtherArray['other']['uvStart'] = 0;
            $reUvOtherArray['other']['uvOrder'] = 0;
            $uvOtherCodeArray = array();
            foreach ($reRows as $key => $row){
                if($row['uvStartPercent']<0){
                   $reUvOtherArray['other']['code'] = 'other';
                   $reUvOtherArray['other']['name'] = '其他';
                   $reUvOtherArray['other']['uvStartPercent'] = $reUvOtherArray['other']['uvStartPercent'] + $row['uvStartPercent'];
                   $reUvOtherArray['other']['uvStart'] = $reUvOtherArray['other']['uvStart'] + $row['uvStart'];
                   $reUvOtherArray['other']['uvOrder'] = $reUvOtherArray['other']['uvOrder'] + $row['uvOrder'];
                   $uvOtherCodeArray[] = "\'{$row['code']}\'";
                } else {
                   $reUvArray[$row['code']]['code'] = $row['code'];
                   $reUvArray[$row['code']]['name'] = $row['name'];
                   $reUvArray[$row['code']]['uvStartPercent'] =  $row['uvStartPercent'];
                   $reUvArray[$row['code']]['uvStart'] =  $row['uvStart'];
                   $reUvArray[$row['code']]['uvOrder'] = $row['uvOrder'];
                }
                
            }
            if($reUvOtherArray['other']['uvStart']>0){
                $reUvArray = array_merge($reUvArray,$reUvOtherArray);
            }
            $uvOtherCodeStr = count($uvOtherCodeArray)>0 ? implode(',',$uvOtherCodeArray) : '';
            $this->view->uvOtherCodeStr = $uvOtherCodeStr;
            
            //合计
            $count['uv']['uvStart'] = 0;
            $count['uv']['uvOrder'] = 0;
			$count['uv']['uvStartPercent'] = 0;
			$count['uv']['orderPercent'] = 0;
            $count['uv']['orderPercentInfo'] = 0;
            $count['uv']['num'] = 0;
            $uvShowArray = array();
            foreach($reUvArray as $key=>$row) {
                //转化率 提交订单
                $orderPercent = $row['uvStart']>0 ? number_format($row['uvOrder']/$row['uvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                //合计
                $count['uv']['uvStart'] = $count['uv']['uvStart'] + $row['uvStart'];
                $count['uv']['uvOrder'] = $count['uv']['uvOrder'] + $row['uvOrder'];
                $count['uv']['uvStartPercent'] = $count['uv']['uvStart']>0 ? '100%' : '0%';
                $orderPercent = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvOrder']/$count['uv']['uvStart'],4)*100 : 0;
                $count['uv']['orderPercent'] = $orderPercent.'%';
                $count['uv']['orderPercentInfo'] = $count['uv']['orderPercentInfo'] + $orderPercent;
                $count['uv']['num'] = $count['uv']['num']+1;
                
                $uvShowArray[$key]['code'] = $row['code'];
                $uvShowArray[$key]['name'] = $row['name'];
                $uvShowArray[$key]['uvStart'] = $row['uvStart'];
                $uvShowArray[$key]['uvStartPercent'] = $row['uvStartPercent'].'%';
                $uvShowArray[$key]['uvOrder'] = $row['uvOrder'];
                $uvShowArray[$key]['orderPercentInfo'] = $orderPercentInfo;
            }
            
            $this->view->uvRows = $uvShowArray;
            $this->view->countAll = $count;
            
            //导出Excel
            if ($vars['export']=='yes'){
                $exportArray = array();
                $exportNum =1;
                foreach ($pvShowArray as $row){
                    $exportNum++;
                    $exportArray['pv']['A'.$exportNum]= $row['name'];
                    $exportArray['pv']['B'.$exportNum]= $row['pvStart'];
                    $exportArray['pv']['C'.$exportNum]= $row['pvStartPercent'];
                    $exportArray['pv']['D'.$exportNum]= $row['pvOrder'];
                    $exportArray['pv']['E'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['pv']['A'.$exportNum]= '总计';
                $exportArray['pv']['B'.$exportNum]= $count['pv']['pvStart'];
                $exportArray['pv']['C'.$exportNum]= $count['pv']['pvStartPercent'];
                $exportArray['pv']['D'.$exportNum]= $count['pv']['pvOrder'];
                $exportArray['pv']['E'.$exportNum]= $count['pv']['orderPercent'];
                
                $exportNum =1;
                foreach ($uvShowArray as $row){
                    $exportNum++;
                    $exportArray['uv']['A'.$exportNum]= $row['name'];
                    $exportArray['uv']['B'.$exportNum]= $row['uvStart'];
                    $exportArray['uv']['C'.$exportNum]= $row['uvStartPercent'];
                    $exportArray['uv']['D'.$exportNum]= $row['uvOrder'];
                    $exportArray['uv']['E'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['uv']['A'.$exportNum]= '总计';
                $exportArray['uv']['B'.$exportNum]= $count['uv']['uvStart'];
                $exportArray['uv']['C'.$exportNum]= $count['uv']['uvStartPercent'];
                $exportArray['uv']['D'.$exportNum]= $count['uv']['uvOrder'];
                $exportArray['uv']['E'.$exportNum]= $count['uv']['orderPercent'];
                
                $table = array();
                $table[0]['tableName'] = '转化率-按渠道(pv)';
                $table[0]['title'] = array('渠道名称','启动次数','启动次数占比(%)','提交订单数量','提交订单转化率');
                $table[0]['con'] = $exportArray['pv'];
                $table[1]['tableName'] = '转化率-按渠道(uv)';
                $table[1]['title'] = array('渠道名称','启动人数','启动人数占比(%)','提交订单人数','提交订单转化率');
                $table[1]['con'] = $exportArray['uv'];
                $this->_model->excelExport($table,"[{$vars['startTime']}_{$vars['endTime']}]{$productCode}-member-export");
            }
            
            
        } elseif ($vars['doType']==2){ //按专题
           
        } elseif ($vars['doType']==3){ //按操作系统
            $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
            
            //--启动----start---------------------
            
            $dayDataModel = new Application_Model_DayData();
            $sql = "SELECT osName,sum(bootNum) as pv,sum(bootClientNum) as uv FROM `{$dayDataModel->getTableName()}` {$where} GROUP BY osName  ORDER BY {$orderBy}";
            
            $startappRows = $dayDataModel ->getAdapter()->fetchAll($sql);
            //--启动----end---------------------
            
            
            
            //提交订单
            $sql = "SELECT osname as osName,SUM(okOrderNum) AS pv,SUM(okOrderClientNum) AS uv  FROM " . $dayDataModel->getTableName() . $where . "  GROUP BY osName ";
            //echo($sql);
            $orderRows = $dayDataModel ->getAdapter()->fetchAll($sql);
            $reOrderRows = array();
            foreach ($orderRows as $key=>$row){
                $row['osName'] = strtolower(trim($row['osName']));
                $reOrderRows[$row['osName']]['pv'] = $row['pv'];
                $reOrderRows[$row['osName']]['uv'] = $row['uv'];
            }
            
            //合计
            $countStartApp = array();
            $countStartApp['pvStart'] = 0;
            $countStartApp['uvStart'] = 0;
            foreach($startappRows as $key=>$row) {
                $countStartApp['pvStart'] = $countStartApp['pvStart'] + $row['pv'];
                $countStartApp['uvStart'] = $countStartApp['uvStart'] + $row['uv'];
            }
            
            $reRows = array();
            foreach($startappRows as $key=>$row) {
                $row['osName'] = strtolower(trim($row['osName']));
                //启动所点比例 
                $reRows[$row['osName']]['pvStartPercent'] = $countStartApp['pvStart']>0 ? number_format($row['pv']/$countStartApp['pvStart'],3)*100 : 0;
                $reRows[$row['osName']]['uvStartPercent'] = $countStartApp['uvStart']>0 ? number_format($row['uv']/$countStartApp['uvStart'],3)*100 : 0;
                
                //启动次数
                $reRows[$row['osName']]['osName'] = $row['osName'];
                $reRows[$row['osName']]['pvStart'] = $row['pv'];
                $reRows[$row['osName']]['uvStart'] = $row['uv'];
                
                
                
                //提交订单
                $reRows[$row['osName']]['pvOrder'] = 0;
                if(isset($reOrderRows[$row['osName']]['pv'])){
                    $reRows[$row['osName']]['pvOrder'] = $reOrderRows[$row['osName']]['pv'];
                }
                $reRows[$row['osName']]['uvOrder'] = 0;
                if(isset($reOrderRows[$row['osName']]['uv'])){
                    $reRows[$row['osName']]['uvOrder'] = $reOrderRows[$row['osName']]['uv'];
                }
                
                
            }
            
           //合计
            $count = array();
            $count['pv']['pvStart'] = 0;
            $count['pv']['pvOrder'] = 0;
			$count['pv']['pvStartPercent'] = 0;
			$count['pv']['orderPercent'] = 0;
            $count['pv']['orderPercentInfo'] = 0;
            $pvShowArray = array();
            foreach($reRows as $key=>$row) {
                //转化率 提交订单
                $orderPercent = $row['pvStart']>0 ? number_format($row['pvOrder']/$row['pvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                //合计
                $count['pv']['pvStart'] = $count['pv']['pvStart'] + $row['pvStart'];
                $count['pv']['pvOrder'] = $count['pv']['pvOrder'] + $row['pvOrder'];
                $count['pv']['pvStartPercent'] = $count['pv']['pvStart']>0 ? '100%' : '0%';
                $orderPercent = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvOrder']/$count['pv']['pvStart'],4)*100 : 0;
                $count['pv']['orderPercent'] = $orderPercent.'%';
                $count['pv']['orderPercentInfo'] = $count['pv']['orderPercentInfo'] + $orderPercent;
                
                $pvShowArray[$key]['osName'] = $row['osName'];
                $pvShowArray[$key]['pvStart'] = $row['pvStart'];
                $pvShowArray[$key]['pvStartPercent'] = $row['pvStartPercent'].'%';
                $pvShowArray[$key]['pvOrder'] = $row['pvOrder'];
                $pvShowArray[$key]['orderPercentInfo'] = $orderPercentInfo;
            }
            
            $count['uv']['uvStart'] = 0;
            $count['uv']['uvOrder'] = 0;
			$count['uv']['uvStartPercent'] = 0;
			$count['uv']['orderPercent'] = 0;
            $count['uv']['orderPercentInfo'] = 0;
            $uvShowArray = array();
            foreach($reRows as $key=>$row) {
                //转化率 提交订单
                $orderPercent = $row['uvStart']>0 ? number_format($row['uvOrder']/$row['uvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                //合计
                $count['uv']['uvStart'] = $count['uv']['uvStart'] + $row['uvStart'];
                $count['uv']['uvOrder'] = $count['uv']['uvOrder'] + $row['uvOrder'];
                $count['uv']['uvStartPercent'] = $count['uv']['uvStart']>0 ? '100%' : '0%';
                $orderPercent = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvOrder']/$count['uv']['uvStart'],4)*100 : 0;
                $count['uv']['orderPercent'] = $orderPercent.'%';
                $count['uv']['orderPercentInfo'] = $count['uv']['orderPercentInfo'] + $orderPercent;
                
                $uvShowArray[$key]['osName'] = $row['osName'];
                $uvShowArray[$key]['uvStart'] = $row['uvStart'];
                $uvShowArray[$key]['uvStartPercent'] = $row['uvStartPercent'].'%';
                $uvShowArray[$key]['uvOrder'] = $row['uvOrder'];
                $uvShowArray[$key]['orderPercentInfo'] = $orderPercentInfo;
            }
            
            
            
            $this->view->pvRows = $pvShowArray;
            $this->view->uvRows = $uvShowArray;
            $this->view->countAll = $count;
            
            
            
            //检查是否有菜单访问权限
            $userLoginModel = Application_Model_UserLogin::getInstance();
            $currentUserRow = $userLoginModel->getLoginedRow();
            $menu = array('module'=>$this->_request->getModuleName(), 'controller'=>$this->_request->getControllerName(), 'action'=>'getdata-count-by-osname');
            $menuIsAccess = $userLoginModel->menuIsAccess($menu, $currentUserRow['id'], $userLoginModel->getUserCurrentRoleId(), $userLoginModel->getUserCurrentProductCode());
            $this->view->ajaxMenuIsAccess = $menuIsAccess;
            
            
            //导出Excel
            if ($vars['export']=='yes'){
                $exportArray = array();
                $exportNum =1;
                foreach ($pvShowArray as $row){
                    $exportNum++;
                    $exportArray['pv']['A'.$exportNum]= $row['osName'];
                    $exportArray['pv']['B'.$exportNum]= $row['pvStart'];
                    $exportArray['pv']['C'.$exportNum]= $row['pvStartPercent'];
                    $exportArray['pv']['D'.$exportNum]= $row['pvOrder'];
                    $exportArray['pv']['E'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['pv']['A'.$exportNum]= '总计';
                $exportArray['pv']['B'.$exportNum]= $count['pv']['pvStart'];
                $exportArray['pv']['C'.$exportNum]= $count['pv']['pvStartPercent'];
                $exportArray['pv']['D'.$exportNum]= $count['pv']['pvOrder'];
                $exportArray['pv']['E'.$exportNum]= $count['pv']['orderPercent'];
                
                $exportNum =1;
                foreach ($uvShowArray as $row){
                    $exportNum++;
                    $exportArray['uv']['A'.$exportNum]= $row['osName'];
                    $exportArray['uv']['B'.$exportNum]= $row['uvStart'];
                    $exportArray['uv']['C'.$exportNum]= $row['uvStartPercent'];
                    $exportArray['uv']['D'.$exportNum]= $row['uvOrder'];
                    $exportArray['uv']['E'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['uv']['A'.$exportNum]= '总计';
                $exportArray['uv']['B'.$exportNum]= $count['uv']['uvStart'];
                $exportArray['uv']['C'.$exportNum]= $count['uv']['uvStartPercent'];
                $exportArray['uv']['D'.$exportNum]= $count['uv']['uvOrder'];
                $exportArray['uv']['E'.$exportNum]= $count['uv']['orderPercent'];
                
                $table = array();
                $table[0]['tableName'] = '转化率-按操作系统(pv)';
                $table[0]['title'] = array('操作系统','启动次数','启动次数占比(%)','提交订单数量','提交订单转化率');
                $table[0]['con'] = $exportArray['pv'];
                $table[1]['tableName'] = '转化率-按操作系统(uv)';
                $table[1]['title'] = array('操作系统','启动人数','启动人数占比(%)','提交订单人数','提交订单转化率');
                $table[1]['con'] = $exportArray['uv'];
                $this->_model->excelExport($table,"[{$vars['startTime']}_{$vars['endTime']}]{$productCode}-osName-export");
            }
            
        } elseif ($vars['doType']==4){ //按地域
            $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
            
            //--启动----start---------------------
            
            $dayAreaDataModel = new Application_Model_DayAreaData();
            $sql = "SELECT province AS name,sum(bootNum) as pv,sum(bootClientNum) as uv FROM `{$dayAreaDataModel->getTableName()}` {$where} GROUP BY name  ORDER BY {$orderBy}";
            $startappRows = $dayAreaDataModel ->getAdapter()->fetchAll($sql);
            //--启动----end---------------------
            
            
            
            //提交订单
            $sql = "SELECT province as name,SUM(okOrderNum) AS pv,SUM(okOrderClientNum) AS uv  FROM " . $dayAreaDataModel->getTableName() . $where . " GROUP BY name ";
            $orderRows = $dayAreaDataModel ->getAdapter()->fetchAll($sql);
            $reOrderRows = array();
            foreach ($orderRows as $key=>$row){
                $row['name'] = strtolower(trim($row['name']));
                if ($row['name']=='其他'){
                    $row['name'] = '国外';
                }
                $reOrderRows[$row['name']]['pv'] = $row['pv'];
                $reOrderRows[$row['name']]['uv'] = $row['uv'];
            }
            
            //合计
            $countStartApp = array();
            $countStartApp['pvStart'] = 0;
            $countStartApp['uvStart'] = 0;
            foreach($startappRows as $key=>$row) {
                $countStartApp['pvStart'] = $countStartApp['pvStart'] + $row['pv'];
                $countStartApp['uvStart'] = $countStartApp['uvStart'] + $row['uv'];
            }
            
            $reRows = array();
            foreach($startappRows as $key=>$row) {
                $row['name'] = strtolower(trim($row['name']));
                if ($row['name']=='其他'){
                    $row['name'] = '国外';
                }
                //启动所点比例 
                $reRows[$row['name']]['pvStartPercent'] = $countStartApp['pvStart']>0 ? number_format($row['pv']/$countStartApp['pvStart'],3)*100 : 0;
                $reRows[$row['name']]['uvStartPercent'] = $countStartApp['uvStart']>0 ? number_format($row['uv']/$countStartApp['uvStart'],3)*100 : 0;
                
                //启动次数
                $reRows[$row['name']]['name'] = $row['name'];
                $reRows[$row['name']]['pvStart'] = $row['pv'];
                $reRows[$row['name']]['uvStart'] = $row['uv'];
                
                
                
                //提交订单
                $reRows[$row['name']]['pvOrder'] = 0;
                if(isset($reOrderRows[$row['name']]['pv'])){
                    $reRows[$row['name']]['pvOrder'] = $reOrderRows[$row['name']]['pv'];
                }
                $reRows[$row['name']]['uvOrder'] = 0;
                if(isset($reOrderRows[$row['name']]['uv'])){
                    $reRows[$row['name']]['uvOrder'] = $reOrderRows[$row['name']]['uv'];
                }
                
                
            }
            
            
            //合计
            $count = array();
            $count['pv']['pvStart'] = 0;
            $count['pv']['pvOrder'] = 0;
			$count['pv']['pvStartPercent'] = 0;
			$count['pv']['orderPercent'] = 0;
            $count['pv']['orderPercentInfo'] = 0;
            $pvShowArray = array();
            foreach($reRows as $key=>$row) {
                //转化率 提交订单
                $orderPercent = $row['pvStart']>0 ? number_format($row['pvOrder']/$row['pvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                //合计
                $count['pv']['pvStart'] = $count['pv']['pvStart'] + $row['pvStart'];
                $count['pv']['pvOrder'] = $count['pv']['pvOrder'] + $row['pvOrder'];
                $count['pv']['pvStartPercent'] = $count['pv']['pvStart']>0 ? '100%' : '0%';
                $orderPercent = $count['pv']['pvStart']>0 ? number_format($count['pv']['pvOrder']/$count['pv']['pvStart'],4)*100 : 0;
                $count['pv']['orderPercent'] = $orderPercent.'%';
                $count['pv']['orderPercentInfo'] = $count['pv']['orderPercentInfo'] + $orderPercent;
                
                $pvShowArray[$key]['name'] = $row['name'];
                $pvShowArray[$key]['pvStart'] = $row['pvStart'];
                $pvShowArray[$key]['pvStartPercent'] = $row['pvStartPercent'].'%';
                $pvShowArray[$key]['pvOrder'] = $row['pvOrder'];
                $pvShowArray[$key]['orderPercentInfo'] = $orderPercentInfo;
            }
            
            $count['uv']['uvStart'] = 0;
            $count['uv']['uvOrder'] = 0;
			$count['uv']['uvStartPercent'] = 0;
			$count['uv']['orderPercent'] = 0;
            $count['uv']['orderPercentInfo'] = 0;
            $uvShowArray = array();
            foreach($reRows as $key=>$row) {
                //转化率 提交订单
                $orderPercent = $row['uvStart']>0 ? number_format($row['uvOrder']/$row['uvStart'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                //合计
                $count['uv']['uvStart'] = $count['uv']['uvStart'] + $row['uvStart'];
                $count['uv']['uvOrder'] = $count['uv']['uvOrder'] + $row['uvOrder'];
                $count['uv']['uvStartPercent'] = $count['uv']['uvStart']>0 ? '100%' : '0%';
                $orderPercent = $count['uv']['uvStart']>0 ? number_format($count['uv']['uvOrder']/$count['uv']['uvStart'],4)*100 : 0;
                $count['uv']['orderPercent'] = $orderPercent.'%';
                $count['uv']['orderPercentInfo'] = $count['uv']['orderPercentInfo'] + $orderPercent;
                
                $uvShowArray[$key]['name'] = $row['name'];
                $uvShowArray[$key]['uvStart'] = $row['uvStart'];
                $uvShowArray[$key]['uvStartPercent'] = $row['uvStartPercent'].'%';
                $uvShowArray[$key]['uvOrder'] = $row['uvOrder'];
                $uvShowArray[$key]['orderPercentInfo'] = $orderPercentInfo;
            }
            
            
            
            $this->view->pvRows = $pvShowArray;
            $this->view->uvRows = $uvShowArray;
            $this->view->countAll = $count;
            
            
            //导出Excel
            if ($vars['export']=='yes'){
                $exportArray = array();
                $exportNum =1;
                foreach ($pvShowArray as $row){
                    $exportNum++;
                    $exportArray['pv']['A'.$exportNum]= $row['name'];
                    $exportArray['pv']['B'.$exportNum]= $row['pvStart'];
                    $exportArray['pv']['C'.$exportNum]= $row['pvStartPercent'];
                    $exportArray['pv']['D'.$exportNum]= $row['pvOrder'];
                    $exportArray['pv']['E'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['pv']['A'.$exportNum]= '总计';
                $exportArray['pv']['B'.$exportNum]= $count['pv']['pvStart'];
                $exportArray['pv']['C'.$exportNum]= $count['pv']['pvStartPercent'];
                $exportArray['pv']['D'.$exportNum]= $count['pv']['pvOrder'];
                $exportArray['pv']['E'.$exportNum]= $count['pv']['orderPercent'];
                
                $exportNum =1;
                foreach ($uvShowArray as $row){
                    $exportNum++;
                    $exportArray['uv']['A'.$exportNum]= $row['name'];
                    $exportArray['uv']['B'.$exportNum]= $row['uvStart'];
                    $exportArray['uv']['C'.$exportNum]= $row['uvStartPercent'];
                    $exportArray['uv']['D'.$exportNum]= $row['uvOrder'];
                    $exportArray['uv']['E'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['uv']['A'.$exportNum]= '总计';
                $exportArray['uv']['B'.$exportNum]= $count['uv']['uvStart'];
                $exportArray['uv']['C'.$exportNum]= $count['uv']['uvStartPercent'];
                $exportArray['uv']['D'.$exportNum]= $count['uv']['uvOrder'];
                $exportArray['uv']['E'.$exportNum]= $count['uv']['orderPercent'];
                
                $table = array();
                $table[0]['tableName'] = '转化率-按地域(pv)';
                $table[0]['title'] = array('地域名称','启动次数','启动次数占比(%)','提交订单数量','提交订单转化率');
                $table[0]['con'] = $exportArray['pv'];
                $table[1]['tableName'] = '转化率-按地域(uv)';
                $table[1]['title'] = array('地域名称','启动人数','启动人数占比(%)','提交订单人数','提交订单转化率');
                $table[1]['con'] = $exportArray['uv'];
                $this->_model->excelExport($table,"[{$vars['startTime']}_{$vars['endTime']}]{$productCode}-province-export");
            }
            
            
            
        } else {
            exit("未法操作");
        }
        $this->view->title = '转化率';
        $this->view->vars = $vars;
         
        
    }
    
    
    //页页转化率 按渠道 展开
    public function getdataAction()
    {
        $vars = array();
        $wheres = array();
        $vars['startTime'] = trim($this->_request->get('startTime'));
        $vars['endTime'] = trim($this->_request->get('endTime'));
        $memberName = trim($this->_request->get('name'));
        $code = trim($this->_request->get('code'));
        $doType = trim($this->_request->get('flag'));
        
        $productCode = Application_Model_UserLogin::getInstance()->getUserCurrentProductCode();
        $wheres[] = "`productCode` = '{$productCode}'";
        
        if ($vars['startTime'] != '') {
            $wheres[] = "`date` >= '{$vars['startTime']}' ";
        }
        if ($vars['endTime'] != '') {
            $wheres[] = "`date` <= '{$vars['endTime']}' ";
        }
        
        $wheres[] ="`date`>='2011-10-13'";
        $endDate = date('Y-m-d',strtotime("-1 day"));
        $wheres[] ="`date`<='{$endDate}'";
        $orderBy = "`pv` DESC";
        
        //清理测试数据
        $wheres[] = $this->_whereByClear2;
        
        $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
        $startappModel = new Application_Model_ActDayDataStartapp();
        if ($memberName == '未知渠道'){
            $leftSql = " c.name IS NULL  ";
        } elseif ($memberName == '其他'){
            $leftSql = " ifnull(c.code, '') in ({$code}) ";
        } else{
            $leftSql = " c.name = '{$memberName}'";
        }
        
        $sql = "
            SELECT a.sourceId,a.sourceSubId,a.pv,a.uv,b.sourceName from (    
            SELECT productCode,sourceId,sourceSubId,sum(pvStart) as pv,sum(uvStart) as uv  from `{$startappModel->getTableName()}` 
            {$where}
            GROUP BY productCode,sourceId,sourceSubId
            ) as a  
            LEFT JOIN mob_source as b on a.productCode = b.productCode and a.sourceId=b.sourceId and a.sourceSubId=b.sourceSubId    
            LEFT JOIN mob_member as c on b.memberCode=c.code    
            where {$leftSql}
            GROUP BY a.sourceId,a.sourceSubId  
        ";
        $startappRows = $startappModel ->getAdapter()->fetchAll($sql);
        //商品详情页
        $pagevisitModel = new Application_Model_ActDayDataPagevisit();
        $sql = "
            SELECT a.sourceId,a.sourceSubId,a.pv,a.uv FROM (    
            SELECT productCode,sourceId,sourceSubId,sum(pv) as pv,sum(uv) as uv  FROM `{$pagevisitModel->getTableName()}` 
            {$where} AND pageId='1007' 
            GROUP BY productCode,sourceId,sourceSubId
            ) as a  
            LEFT JOIN mob_source as b on a.productCode = b.productCode and a.sourceId=b.sourceId and a.sourceSubId=b.sourceSubId    
            LEFT JOIN mob_member as c on b.memberCode=c.code    
            WHERE {$leftSql}
            GROUP BY a.sourceId,a.sourceSubId  
        ";
        $productInfoRows = $pagevisitModel ->getAdapter()->fetchAll($sql);
        $reProductInfoRows = array();
        foreach ($productInfoRows as $key=>$row){
            $reProductInfoRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'] = $row['pv'];
            $reProductInfoRows[$row['sourceId'].'-'.$row['sourceSubId']]['uv'] = $row['uv'];
        }
        
        //结算中心
        $pagevisitModel = new Application_Model_ActDayDataPagevisit();
        $sql = "
            SELECT a.sourceId,a.sourceSubId,a.pv,a.uv FROM (    
            SELECT productCode,sourceId,sourceSubId,sum(pv) as pv,sum(uv) as uv  FROM `{$pagevisitModel->getTableName()}` 
            {$where} AND pageId='1012' 
            GROUP BY productCode,sourceId,sourceSubId
            ) as a  
            LEFT JOIN mob_source as b on a.productCode = b.productCode and a.sourceId=b.sourceId and a.sourceSubId=b.sourceSubId    
            LEFT JOIN mob_member as c on b.memberCode=c.code    
            WHERE {$leftSql}
            GROUP BY a.sourceId,a.sourceSubId  
        ";
        
        $toCountRows = $pagevisitModel ->getAdapter()->fetchAll($sql);
        $reToCountRows = array();
        foreach ($toCountRows as $key=>$row){
            $reToCountRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'] = $row['pv'];
            $reToCountRows[$row['sourceId'].'-'.$row['sourceSubId']]['uv'] = $row['uv'];
        }
        
        //加入购物车
        $sql = "
            SELECT a.sourceId,a.sourceSubId,a.pv,a.uv FROM (    
            SELECT productCode,sourceId,sourceSubId,sum(pv) as pv,sum(uv) as uv  FROM `{$this ->_model->getTableName()}` 
            {$where} AND pageId='1003' 
            GROUP BY productCode,sourceId,sourceSubId
            ) as a  
            LEFT JOIN mob_source as b on a.productCode = b.productCode and a.sourceId=b.sourceId and a.sourceSubId=b.sourceSubId    
            LEFT JOIN mob_member as c on b.memberCode=c.code    
            WHERE {$leftSql}
            GROUP BY a.sourceId,a.sourceSubId  
        ";
        $shoppingRows = $this ->_model ->getAdapter()->fetchAll($sql);
        $reShoppingRows = array();
        foreach ($shoppingRows as $key=>$row){
            $reShoppingRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'] = $row['pv'];
            $reShoppingRows[$row['sourceId'].'-'.$row['sourceSubId']]['uv'] = $row['uv'];
        }
        
        //提交订单
        $sql = "
            SELECT a.sourceId,a.sourceSubId,a.pv,a.uv FROM (    
            SELECT productCode,sourceId,sourceSubId,sum(pv) as pv,sum(uv) as uv  FROM `{$this ->_model->getTableName()}` 
            {$where} AND pageId='1007' 
            GROUP BY productCode,sourceId,sourceSubId
            ) as a  
            LEFT JOIN mob_source as b on a.productCode = b.productCode and a.sourceId=b.sourceId and a.sourceSubId=b.sourceSubId    
            LEFT JOIN mob_member as c on b.memberCode=c.code    
            WHERE {$leftSql}
            GROUP BY a.sourceId,a.sourceSubId  
        ";
        $orderRows = $this ->_model ->getAdapter()->fetchAll($sql);
        $reOrderRows = array();
        foreach ($orderRows as $key=>$row){
            $reOrderRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'] = $row['pv'];
            $reOrderRows[$row['sourceId'].'-'.$row['sourceSubId']]['uv'] = $row['uv'];
        }
        
        $count = array();
        $count['pv'] = 0;
        $count['uv'] = 0;
        foreach ($startappRows as $key =>$row){
             $count['pv'] += $row['pv'];
             $count['uv'] += $row['uv'];
        }
        
        $result = "";
        if ($doType==1){
            if (count($startappRows)>0){
                
                $result .= "
                        <tr class=\"subject\">
                            <td >子渠道</td>
                            <td colspan=\"2\" align=\"center\">启动</td>
                            <td>商品详情页</td>
                            <td colspan=\"2\" align=\"center\">加入购物车</td>
                            <td colspan=\"2\" align=\"center\">加入购物车商品</td>
                            <td colspan=\"2\" align=\"center\">进入订单页面</td>
                            <td colspan=\"2\" align=\"center\">提交订单</td>
                        </tr>
                        <tr class=\"subject\">
                            <td>名称</td>
                            <td>次数</td>
                            <td>占比(%)</td>
                            <td>浏览次数</td>
                            <td>次数</td>
                            <td>转化率</td>
                            <td>数量</td>
                            <td>转化率</td>
                            <td>次数</td>
                            <td>转化率</td>
                            <td>数量</td>
                            <td>转化率</td>
                        </tr>";
                foreach ($startappRows as $key =>$row){
                    $pvPercent = $count['pv']>0 ? number_format($row['pv']/$count['pv'],4)*100 : 0;
                    //商品详情
                    $productInfo = 0;
                    if (isset($reProductInfoRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'])){
                        $productInfo = $reProductInfoRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'];
                    }
                    //结算中心
                    $toCount = 0;
                    if (isset($reToCountRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'])){
                        $toCount = $reToCountRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'];
                    }
                    //结算中心   转化率
                    $toCountPercent = $row['pv']>0 ? number_format($toCount/$row['pv'],4)*100 : 0;
                    $toCountPercent = $toCountPercent>100 ? 100 : $toCountPercent ;
                    //加入购物车
                    $shopping = 0;
                    if (isset($reShoppingRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'])){
                        $shopping = $reShoppingRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'];
                    }
                    //加入购物车  转化率
                    $shoppingPercent = $row['pv']>0 ? number_format($shopping/$row['pv'],4)*100 : 0;
                    $shoppingPercent = $shoppingPercent>100 ? 100 : $shoppingPercent ;
                    //提交订单
                    $order = 0;
                    if (isset($reOrderRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'])){
                        $order = $reOrderRows[$row['sourceId'].'-'.$row['sourceSubId']]['pv'];
                    }
                    //提交订单  转化率
                    $orderPercent = $row['pv']>0 ? number_format($order/$row['pv'],4)*100 : 0;
                    $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                    $result .= " 
                                 <tr>
                                 <td class=\"textLeft\">{$row['sourceName']}</td>
                                 <td>{$row['pv']}</td>
                                 <td>{$pvPercent}%</td>
                                 <td>{$productInfo}</td>
                                 <td>{$shopping}</td>
                                 <td>{$shoppingPercent}%</td>
                                 <td>{$shopping}</td>
                                 <td>{$shoppingPercent}%</td>
                                 <td>{$toCount}</td>
                                 <td>{$toCountPercent}%</td>
                                 <td>{$order}</td>
                                 <td>{$orderPercent}%</td>
                                 </tr>
                    ";
                }
            }
        } elseif ($doType==2){
        if (count($startappRows)>0){
                
                $result .= "
                        <tr class=\"subject\">
                            <td >子渠道</td>
                            <td colspan=\"2\" align=\"center\">启动</td>
                            <td colspan=\"2\" align=\"center\">进入商品详情页</td>
                            <td colspan=\"2\" align=\"center\">加入购物车</td>
                            <td colspan=\"2\" align=\"center\">提交订单</td>
                        </tr>
                        <tr class=\"subject\">
                            <td>名称</td>
                            <td>人数</td>
                            <td>占比(%)</td>
                            <td>人数</td>
                            <td>转化率</td>
                            <td>人数</td>
                            <td>转化率</td>
                            <td>人数</td>
                            <td>转化率</td>
                        </tr>";
                foreach ($startappRows as $key =>$row){
                    $uvPercent = $count['uv']>0 ? number_format($row['uv']/$count['uv'],4)*100 : 0;
                    //商品详情
                    $productInfo = 0;
                    if (isset($reProductInfoRows[$row['sourceId'].'-'.$row['sourceSubId']]['uv'])){
                        $productInfo = $reProductInfoRows[$row['sourceId'].'-'.$row['sourceSubId']]['uv'];
                    }
                    //商品详情   转化率
                    $productInfoPercent = $row['uv']>0 ? number_format($productInfo/$row['uv'],4)*100 : 0;
                    //加入购物车
                    $shopping = 0;
                    if (isset($reShoppingRows[$row['sourceId'].'-'.$row['sourceSubId']]['uv'])){
                        $shopping = $reShoppingRows[$row['sourceId'].'-'.$row['sourceSubId']]['uv'];
                    }
                    //加入购物车  转化率
                    $shoppingPercent = $row['uv']>0 ? number_format($shopping/$row['uv'],4)*100 : 0;
                    //提交订单
                    $order = 0;
                    if (isset($reOrderRows[$row['sourceId'].'-'.$row['sourceSubId']]['uv'])){
                        $order = $reOrderRows[$row['sourceId'].'-'.$row['sourceSubId']]['uv'];
                    }
                    //提交订单  转化率
                    $orderPercent = $row['uv']>0 ? number_format($order/$row['uv'],4)*100 : 0;
                    $result .= " <tr>
                                 <td class=\"textLeft\">{$row['sourceName']}</td>
                                 <td>{$row['uv']}</td>
                                 <td>{$uvPercent}%</td>
                                 <td>{$productInfo}</td>
                                 <td>{$productInfoPercent}%</td>
                                 <td>{$shopping}</td>
                                 <td>{$shoppingPercent}%</td>
                                 <td>{$order}</td>
                                 <td>{$orderPercent}%</td>
                                 </tr>
                    ";
                }
            }
        }
        exit($result);
    }
    
    /*
     * 转化率按渠道 展开
     */
    public function getdataCountAction()
    {
        $vars = array();
        $wheres = array();
        $vars['startTime'] = trim($this->_request->get('startTime'));
        $vars['endTime'] = trim($this->_request->get('endTime'));
        $memberName = trim($this->_request->get('name'));
        $code = trim($this->_request->get('code'));
        $doType = trim($this->_request->get('flag'));
        
        $productCode = Application_Model_UserLogin::getInstance()->getUserCurrentProductCode();
        $wheres[] = "`productCode` = '{$productCode}'";
        
        if ($vars['startTime'] != '') {
            $wheres[] = "`date` >= '{$vars['startTime']}' ";
        }
        if ($vars['endTime'] != '') {
            $wheres[] = "`date` <= '{$vars['endTime']}' ";
        }
        
        $orderBy = "`pv` DESC";
        
        
        $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
        $dayDataModel = new Application_Model_DayData();
        $leftSql = '';
        if ($memberName == '未知渠道'){
            $leftSql = " c.name IS NULL ";
        } elseif ($memberName == '其他'){
            $leftSql = " ifnull(c.code, '') in ({$code}) ";
        } else{
            $leftSql = " c.name = '{$memberName}' ";
        }
        
        $sql = "SELECT a.sourceId,a.sourceSubId,a.bootNum as pv,a.bootClientNum as uv,a.okOrderNum as orderPv,a.okOrderClientNum as orderUv,b.sourceName FROM (    
                SELECT productCode,sourceId,sourceSubId,sum(bootNum) as bootNum,sum(bootClientNum) as bootClientNum,sum(okOrderNum) as okOrderNum,sum(okOrderClientNum) as okOrderClientNum FROM `{$dayDataModel->getTableName()}` 
                {$where}
                GROUP BY productCode,sourceId,sourceSubId
                ) as a  
                LEFT JOIN  mob_source as b on a.productCode = b.productCode and a.sourceId=b.sourceId and a.sourceSubId=b.sourceSubId    
                LEFT JOIN mob_member as c on b.memberCode=c.code    
                WHERE {$leftSql}
                GROUP BY a.sourceId,a.sourceSubId  ";
        $startappRows = $dayDataModel ->getAdapter()->fetchAll($sql);
        
        
        $count = array();
        $count['pv'] = 0;
        $count['uv'] = 0;
        foreach ($startappRows as $key =>$row){
             $count['pv'] += $row['pv'];
             $count['uv'] += $row['uv'];
        }
        
        $result = "";
        if ($doType==1){
            if (count($startappRows)>0){
                $result .= "
                        <tr class=\"subject\">
                            <td >子渠道</td>
                            <td colspan=\"2\" align=\"center\">启动</td>
                            <td colspan=\"2\" align=\"center\">提交订单</td>
                        </tr>
                        <tr class=\"subject\">
                            <td>名称</td>
                            <td>次数</td>
                            <td>占比(%)</td>
                            <td>数量</td>
                            <td>转化率</td>
                        </tr>";
                
                foreach ($startappRows as $key =>$row){
                    $pvPercent = $count['pv']>0 ? number_format($row['pv']/$count['pv'],4)*100 : 0;
                    
                    //提交订单
                    $order = $row['orderPv'];
                    //提交订单  转化率
                    $orderPercent = $row['pv']>0 ? number_format($order/$row['pv'],4)*100 : 0;
                    $result .= " <tr>
                                 <td class=\"textLeft\">{$row['sourceName']}</td>
                                 <td>{$row['pv']}</td>
                                 <td>{$pvPercent}%</td>
                                 <td>{$order}</td>
                                 <td>{$orderPercent}%</td>
                                 </tr>
                    ";
                }
            }
        } elseif ($doType==2){
        if (count($startappRows)>0){
                $result .= "
                        <tr class=\"subject\">
                            <td >子渠道</td>
                            <td colspan=\"2\" align=\"center\">启动</td>
                            <td colspan=\"2\" align=\"center\">提交订单</td>
                        </tr>
                        <tr class=\"subject\">
                            <td>名称</td>
                            <td>次数</td>
                            <td>占比(%)</td>
                            <td>人数</td>
                            <td>转化率</td>
                        </tr>";
                foreach ($startappRows as $key =>$row){
                    $uvPercent = $count['uv']>0 ? number_format($row['uv']/$count['uv'],4)*100 : 0;
                    
                    //提交订单
                    $order = $row['orderUv'];
                    //提交订单  转化率
                    $orderPercent = $row['uv']>0 ? number_format($order/$row['uv'],4)*100 : 0;
                    $result .= " <tr>
                                 <td class=\"textLeft\">{$row['sourceName']}</td>
                                 <td>{$row['uv']}</td>
                                 <td>{$uvPercent}%</td>
                                 <td>{$order}</td>
                                 <td>{$orderPercent}%</td>
                                 </tr>
                    ";
                }
            }
        }
        exit($result);
    }
    
    
    
    
    /*
     * 页面转化率 按操作系统 展开
     */ 
    public function getdataByOsnameAction()
    {
        $vars = array();
        $wheres = array();
        $vars['startTime'] = trim($this->_request->get('startTime'));
        $vars['endTime'] = trim($this->_request->get('endTime'));
        $osName = trim($this->_request->get('name'));
        $doType = trim($this->_request->get('flag'));
        
        $productCode = Application_Model_UserLogin::getInstance()->getUserCurrentProductCode();
        $wheres[] = "`productCode` = '{$productCode}'";
        
        if ($vars['startTime'] != '') {
            $wheres[] = "`date` >= '{$vars['startTime']}' ";
        }
        if ($vars['endTime'] != '') {
            $wheres[] = "`date` <= '{$vars['endTime']}' ";
        }
        
        $wheres[] ="`date`>='2011-10-13'";
        $endDate = date('Y-m-d',strtotime("-1 day"));
        $wheres[] ="`date`<='{$endDate}'";
        $orderBy = "`pv` DESC";
        
        if ($osName=='未知'){
            $wheres[] ="ifnull(osName, '')=''";
        }else{
            $wheres[] ="`osName`='{$osName}'";
        }
        //清理测试数据
        $wheres[] = $this->_whereByClear2;
        $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
        $startappModel = new Application_Model_ActDayDataStartapp();
        $sql = "SELECT osName,`version`,sum(pvStart) as pv,sum(uvStart) as uv FROM `{$startappModel->getTableName()}` {$where} GROUP BY osName,version ORDER BY {$orderBy}";
        $startappRows = $startappModel ->getAdapter()->fetchAll($sql);
        
        //商品详情页
        $pagevisitModel = new Application_Model_ActDayDataPagevisit();
        $sql = "SELECT osName,`version`,sum(pv) as pv,sum(uv) as uv FROM `{$pagevisitModel->getTableName()}` {$where} AND pageId='1007' GROUP BY osName,version ORDER BY {$orderBy}";
        $productInfoRows = $pagevisitModel ->getAdapter()->fetchAll($sql);
        $reProductInfoRows = array();
        foreach ($productInfoRows as $key=>$row){
            $reProductInfoRows[$row['osName'].'-'.$row['version']]['pv'] = $row['pv'];
            $reProductInfoRows[$row['osName'].'-'.$row['version']]['uv'] = $row['uv'];
        }
        //结算中心
        $sql = "SELECT osName,`version`,sum(pv) as pv,sum(uv) as uv FROM `{$pagevisitModel->getTableName()}` {$where} AND pageId='1012' GROUP BY osName,version ORDER BY {$orderBy}";
        $toCountRows = $pagevisitModel ->getAdapter()->fetchAll($sql);
        $reToCountRows = array();
        foreach ($toCountRows as $key=>$row){
            $reToCountRows[$row['osName'].'-'.$row['version']]['pv'] = $row['pv'];
            $reToCountRows[$row['osName'].'-'.$row['version']]['uv'] = $row['uv'];
        }
        //加入购物车
        $sql = "SELECT osName,`version`,sum(pv) as pv,sum(uv) as uv FROM `{$this ->_model->getTableName()}` {$where} AND pageId='1003' GROUP BY osName,version ORDER BY {$orderBy}";
        $shoppingRows = $this ->_model ->getAdapter()->fetchAll($sql);
        $reShoppingRows = array();
        foreach ($shoppingRows as $key=>$row){
            $reShoppingRows[$row['osName'].'-'.$row['version']]['pv'] = $row['pv'];
            $reShoppingRows[$row['osName'].'-'.$row['version']]['uv'] = $row['uv'];
        }
        //提交订单
        $sql = "SELECT osName,`version`, sum(pv) as pv,sum(uv) as uv FROM `{$this ->_model->getTableName()}` {$where} AND pageId='1007' GROUP BY osName,version ORDER BY {$orderBy}";
        $orderRows = $this ->_model ->getAdapter()->fetchAll($sql);
        $reOrderRows = array();
        foreach ($orderRows as $key=>$row){
            $reOrderRows[$row['osName'].'-'.$row['version']]['pv'] = $row['pv'];
            $reOrderRows[$row['osName'].'-'.$row['version']]['uv'] = $row['uv'];
        }
        
        $count = array();
        $count['pv'] = 0;
        $count['uv'] = 0;
        foreach ($startappRows as $key =>$row){
             $count['pv'] += $row['pv'];
             $count['uv'] += $row['uv'];
        }
        $result = "";
        if ($doType==1){
            if (count($startappRows)>0){
                
                $result .= "
                        <tr class=\"subject\">
                            <td >版本号</td>
                            <td colspan=\"2\" align=\"center\">启动</td>
                            <td>商品详情页</td>
                            <td colspan=\"2\" align=\"center\">加入购物车</td>
                            <td colspan=\"2\" align=\"center\">加入购物车商品</td>
                            <td colspan=\"2\" align=\"center\">进入订单页面</td>
                            <td colspan=\"2\" align=\"center\">提交订单</td>
                        </tr>
                        <tr class=\"subject\">
                            <td>名称</td>
                            <td>次数</td>
                            <td>占比(%)</td>
                            <td>浏览次数</td>
                            <td>次数</td>
                            <td>转化率</td>
                            <td>数量</td>
                            <td>转化率</td>
                            <td>次数</td>
                            <td>转化率</td>
                            <td>数量</td>
                            <td>转化率</td>
                        </tr>";
                foreach ($startappRows as $key =>$row){
                    $pvPercent = $count['pv']>0 ? number_format($row['pv']/$count['pv'],4)*100 : 0;
                    //商品详情
                    $productInfo = 0;
                    if (isset($reProductInfoRows[$row['osName'].'-'.$row['version']]['pv'])){
                        $productInfo = $reProductInfoRows[$row['osName'].'-'.$row['version']]['pv'];
                    }
                    //结算中心
                    $toCount = 0;
                    if (isset($reToCountRows[$row['osName'].'-'.$row['version']]['pv'])){
                        $toCount = $reToCountRows[$row['osName'].'-'.$row['version']]['pv'];
                    }
                    //结算中心   转化率
                    $toCountPercent = $row['pv']>0 ? number_format($toCount/$row['pv'],4)*100 : 0;
                    $toCountPercent = $toCountPercent>100 ? 100 : $toCountPercent ;
                    //加入购物车
                    $shopping = 0;
                    if (isset($reShoppingRows[$row['osName'].'-'.$row['version']]['pv'])){
                        $shopping = $reShoppingRows[$row['osName'].'-'.$row['version']]['pv'];
                    }
                    //加入购物车  转化率
                    $shoppingPercent = $row['pv']>0 ? number_format($shopping/$row['pv'],4)*100 : 0;
                    $shoppingPercent = $shoppingPercent>100 ? 100 : $shoppingPercent ;
                    //提交订单
                    $order = 0;
                    if (isset($reOrderRows[$row['osName'].'-'.$row['version']]['pv'])){
                        $order = $reOrderRows[$row['osName'].'-'.$row['version']]['pv'];
                    }
                    //提交订单  转化率
                    $orderPercent = $row['pv']>0 ? number_format($order/$row['pv'],4)*100 : 0;
                    $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                    $result .= " 
                                 <tr>
                                 <td class=\"textLeft\">{$row['version']}</td>
                                 <td>{$row['pv']}</td>
                                 <td>{$pvPercent}%</td>
                                 <td>{$productInfo}</td>
                                 <td>{$shopping}</td>
                                 <td>{$shoppingPercent}%</td>
                                 <td>{$shopping}</td>
                                 <td>{$shoppingPercent}%</td>
                                 <td>{$toCount}</td>
                                 <td>{$toCountPercent}%</td>
                                 <td>{$order}</td>
                                 <td>{$orderPercent}%</td>
                                 </tr>
                    ";
                }
            }
        } elseif ($doType==2){
        if (count($startappRows)>0){
                
                $result .= "
                        <tr class=\"subject\">
                            <td >版本号</td>
                            <td colspan=\"2\" align=\"center\">启动</td>
                            <td colspan=\"2\" align=\"center\">进入商品详情页</td>
                            <td colspan=\"2\" align=\"center\">加入购物车</td>
                            <td colspan=\"2\" align=\"center\">提交订单</td>
                        </tr>
                        <tr class=\"subject\">
                            <td>名称</td>
                            <td>人数</td>
                            <td>占比(%)</td>
                            <td>人数</td>
                            <td>转化率</td>
                            <td>人数</td>
                            <td>转化率</td>
                            <td>人数</td>
                            <td>转化率</td>
                        </tr>";
                foreach ($startappRows as $key =>$row){
                    $uvPercent = $count['uv']>0 ? number_format($row['uv']/$count['uv'],4)*100 : 0;
                    //商品详情
                    $productInfo = 0;
                    if (isset($reProductInfoRows[$row['osName'].'-'.$row['version']]['uv'])){
                        $productInfo = $reProductInfoRows[$row['osName'].'-'.$row['version']]['uv'];
                    }
                    //商品详情   转化率
                    $productInfoPercent = $row['uv']>0 ? number_format($productInfo/$row['uv'],4)*100 : 0;
                    //加入购物车
                    $shopping = 0;
                    if (isset($reShoppingRows[$row['osName'].'-'.$row['version']]['uv'])){
                        $shopping = $reShoppingRows[$row['osName'].'-'.$row['version']]['uv'];
                    }
                    //加入购物车  转化率
                    $shoppingPercent = $row['uv']>0 ? number_format($shopping/$row['uv'],4)*100 : 0;
                    //提交订单
                    $order = 0;
                    if (isset($reOrderRows[$row['osName'].'-'.$row['version']]['uv'])){
                        $order = $reOrderRows[$row['osName'].'-'.$row['version']]['uv'];
                    }
                    //提交订单  转化率
                    $orderPercent = $row['uv']>0 ? number_format($order/$row['uv'],4)*100 : 0;
                    $result .= " <tr>
                                 <td class=\"textLeft\">{$row['version']}</td>
                                 <td>{$row['uv']}</td>
                                 <td>{$uvPercent}%</td>
                                 <td>{$productInfo}</td>
                                 <td>{$productInfoPercent}%</td>
                                 <td>{$shopping}</td>
                                 <td>{$shoppingPercent}%</td>
                                 <td>{$order}</td>
                                 <td>{$orderPercent}%</td>
                                 </tr>
                    ";
                }
            }
        }
        
        exit($result);
    }
    
    /*
     * 转化率按渠道 展开
     */
    public function getdataCountByOsnameAction()
    {
        $vars = array();
        $wheres = array();
        $vars['startTime'] = trim($this->_request->get('startTime'));
        $vars['endTime'] = trim($this->_request->get('endTime'));
        $osName = trim($this->_request->get('name'));
        $doType = trim($this->_request->get('flag'));
        
        $productCode = Application_Model_UserLogin::getInstance()->getUserCurrentProductCode();
        $wheres[] = "`productCode` = '{$productCode}'";
        
        if ($vars['startTime'] != '') {
            $wheres[] = "`date` >= '{$vars['startTime']}' ";
        }
        if ($vars['endTime'] != '') {
            $wheres[] = "`date` <= '{$vars['endTime']}' ";
        }
        
        $orderBy = "`pv` DESC";
        
        if ($osName=='未知'){
            $wheres[] ="ifnull(osName, '')=''";
        }else{
            $wheres[] ="`osName`='{$osName}'";
        }
        $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
        $clientVersionDayDataModel = new Application_Model_ClientVersionDayData();
        
        $sql = "SELECT `version`,sum(bootNum) as pv,sum(bootClientNum) as uv,sum(okOrderNum) as orderPv,sum(okOrderClientNum) as orderUv FROM `{$clientVersionDayDataModel->getTableName()}` 
                {$where}
                GROUP BY version ORDER BY{$orderBy}
                 ";
        $startappRows = $clientVersionDayDataModel ->getAdapter()->fetchAll($sql);
        
        $count = array();
        $count['pv'] = 0;
        $count['uv'] = 0;
        foreach ($startappRows as $key =>$row){
             $count['pv'] += $row['pv'];
             $count['uv'] += $row['uv'];
        }
        
        $result = "";
        if ($doType==1){
            if (count($startappRows)>0){
                $result .= "
                        <tr class=\"subject\">
                            <td >版本号</td>
                            <td colspan=\"2\" align=\"center\">启动</td>
                            <td colspan=\"2\" align=\"center\">提交订单</td>
                        </tr>
                        <tr class=\"subject\">
                            <td>名称</td>
                            <td>次数</td>
                            <td>占比(%)</td>
                            <td>数量</td>
                            <td>转化率</td>
                        </tr>";
                
                foreach ($startappRows as $key =>$row){
                    $pvPercent = $count['pv']>0 ? number_format($row['pv']/$count['pv'],4)*100 : 0;
                    
                    //提交订单
                    $order = $row['orderPv'];
                    //提交订单  转化率
                    $orderPercent = $row['pv']>0 ? number_format($order/$row['pv'],4)*100 : 0;
                    $result .= " <tr>
                                 <td class=\"textLeft\">{$row['version']}</td>
                                 <td>{$row['pv']}</td>
                                 <td>{$pvPercent}%</td>
                                 <td>{$order}</td>
                                 <td>{$orderPercent}%</td>
                                 </tr>
                    ";
                }
            }
        } elseif ($doType==2){
        if (count($startappRows)>0){
                $result .= "
                        <tr class=\"subject\">
                            <td >版本号</td>
                            <td colspan=\"2\" align=\"center\">启动</td>
                            <td colspan=\"2\" align=\"center\">提交订单</td>
                        </tr>
                        <tr class=\"subject\">
                            <td>名称</td>
                            <td>次数</td>
                            <td>占比(%)</td>
                            <td>人数</td>
                            <td>转化率</td>
                        </tr>";
                foreach ($startappRows as $key =>$row){
                    $uvPercent = $count['uv']>0 ? number_format($row['uv']/$count['uv'],4)*100 : 0;
                    
                    //提交订单
                    $order = $row['orderUv'];
                    //提交订单  转化率
                    $orderPercent = $row['uv']>0 ? number_format($order/$row['uv'],4)*100 : 0;
                    $result .= " <tr>
                                 <td class=\"textLeft\">{$row['version']}</td>
                                 <td>{$row['uv']}</td>
                                 <td>{$uvPercent}%</td>
                                 <td>{$order}</td>
                                 <td>{$orderPercent}%</td>
                                 </tr>
                    ";
                }
            }
        }
        exit($result);
    }
    
    
    /**
     * wap转化率
     * 
     * @return void
     */
    public function wapAction()
    {        
        //设置URL模板以及条件
        $urls = array();
        $vars = array();
        $wheres = array();
        $vars['dateType']  = trim($this->_request->get('dateType')) ? trim($this->_request->get('dateType')) : 1;
        $vars['doType']    = trim($this->_request->get('doType')) ? trim($this->_request->get('doType')) : 1;
        $vars['startTime'] = trim($this->_request->get('startTime'));
        $vars['endTime']   = trim($this->_request->get('endTime'));
        $vars['export']   = trim($this->_request->get('export'))!='' ? trim($this->_request->get('export')) :'no';
        
        if ($vars['dateType']==1){
            $vars['startTime'] = date('Y-m-d',strtotime("-1 day"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==2){
            $vars['startTime'] = date('Y-m-d',strtotime("-8 day"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==3){
            $vars['startTime'] = date('Y-m-d',strtotime("-31 day"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==4){
            $vars['startTime'] = date('Y-m-d',strtotime("-3 months"));
            $vars['endTime']   = date('Y-m-d',strtotime("-1 day"));
        } elseif ($vars['dateType']==5){
            $vars['startTime'] = '';
            $vars['endTime']   = '';
        }
        
        $urls = $vars;
        $productCode = Application_Model_UserLogin::getInstance()->getUserCurrentProductCode();
        $wheres[] = "`productCode` = '{$productCode}'";
        
        if ($vars['startTime'] != '') {
            $wheres[] = "`date` >= '{$vars['startTime']}' ";
        }
        if ($vars['endTime'] != '') {
            $wheres[] = "`date` <= '{$vars['endTime']}' ";
        }
        
        
        $orderBy = "`pv` DESC";
        if ($vars['doType']==1){ //按渠道
            $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
            $dayDataWapModel = new Application_Model_DayDataWap();
            $sourceModel = new Application_Model_Source();
            $sql = "
                     SELECT `code`,MAX(`name`) AS name,SUM(num) AS num,SUM(pv) AS pv,SUM(uv) AS uv FROM (
                        SELECT a.*,b.name,b.code FROM 
                        (
                            SELECT productcode,sourceId,sourceSubId,SUM(okOrderNum) AS num,SUM(pv) AS pv,SUM(uv) AS uv  FROM " . $dayDataWapModel->getTableName() . "
                            " . $where . "
                            GROUP BY productcode,sourceid,sourceSubId
                        ) AS a
                        LEFT JOIN
                        (
                            SELECT `name`,`code`,productcode,sourceId,sourcesubId FROM  " . $sourceModel->getTableName() . "  LEFT JOIN `mob_member` ON mob_source.`memberCode`=`mob_member`.`code` 
                            WHERE productcode='" . $productCode . "'
                        ) AS b 
                        ON a.productcode=b.productcode AND a.sourceid=b.sourceid 
                        AND a.sourcesubid=b.sourcesubid
                    )aaa GROUP BY `code` 
                  ";
            $orderRows = $dayDataWapModel ->getAdapter()->fetchAll($sql);
            //合计
            $countApp = array();
            $countApp['pv'] = 0;
            $countApp['uv'] = 0;
            foreach($orderRows as $key=>$row) {
                $countApp['pv'] = $countApp['pv'] + $row['pv'];
                $countApp['uv'] = $countApp['uv'] + $row['uv'];
            }
            
            $reRows = array();
            foreach($orderRows as $key=>$row) {
                //启动所点比例 
                $reRows[$row['code']]['pvPercent'] = $countApp['pv']>0 ? number_format($row['pv']/$countApp['pv'],4)*100 : 0;
                $reRows[$row['code']]['uvPercent'] = $countApp['uv']>0 ? number_format($row['uv']/$countApp['uv'],4)*100 : 0;
                //启动次数
                $reRows[$row['code']]['code'] = $row['code'];
                $reRows[$row['code']]['name'] = $row['name'];
                $reRows[$row['code']]['pv'] = $row['pv'];
                $reRows[$row['code']]['uv'] = $row['uv'];
                //提交订单
                $reRows[$row['code']]['pvOrder'] = $row['num'];
            }
            //重组
            //pv
            $rePvArray = array();
            $rePvOtherArray = array();
            $rePvOtherArray['other']['code'] = '';
            $rePvOtherArray['other']['name'] = '';
            $rePvOtherArray['other']['pvPercent'] = 0;
            $rePvOtherArray['other']['pv'] = 0;
            $rePvOtherArray['other']['pvOrder'] = 0;
            $pvOtherCodeArray = array();
            foreach ($reRows as $key => $row){
                if($row['pvPercent']<0){
                   $rePvOtherArray['other']['code'] = 'other';
                   $rePvOtherArray['other']['name'] = '其他';
                   $rePvOtherArray['other']['pvPercent'] = $rePvOtherArray['other']['pvPercent'] + $row['pvPercent'];
                   $rePvOtherArray['other']['pv'] = $rePvOtherArray['other']['pv'] + $row['pv'];
                   $rePvOtherArray['other']['pvOrder'] = $rePvOtherArray['other']['pvOrder'] + $row['pvOrder'];
                   $pvOtherCodeArray[] = "\'{$row['code']}\'";
                } else {
                   $rePvArray[$row['code']]['code'] = $row['code'];
                   $rePvArray[$row['code']]['name'] = $row['name'];
                   $rePvArray[$row['code']]['pvPercent'] =  $row['pvPercent'];
                   $rePvArray[$row['code']]['pv'] =  $row['pv'];
                   $rePvArray[$row['code']]['pvOrder'] = $row['pvOrder'];
                }
            }
            if($rePvOtherArray['other']['pv']>0){
                $rePvArray = array_merge($rePvArray,$rePvOtherArray);
            }
            $pvOtherCodeStr = count($pvOtherCodeArray)>0 ? implode(',',$pvOtherCodeArray) : '';
            $this->view->pvOtherCodeStr = $pvOtherCodeStr;
            
            //合计
            $count = array();
            $count['pv']['pv'] = 0;
            $count['pv']['pvOrder'] = 0;
			$count['pv']['pvPercent'] = 0;
			$count['pv']['orderPercent'] = 0;
            $count['pv']['orderPercentInfo'] = 0;
            $count['pv']['num'] = 0;
            $pvShowArray = array();
            foreach($rePvArray as $key=>$row) {
                //转化率 提交订单
                $orderPercent = $row['pv']>0 ? number_format($row['pvOrder']/$row['pv'],4)*100 : 0 ;
                $orderPercent = $orderPercent>100 ? 100 : $orderPercent ;
                $orderPercentInfo =  $orderPercent."%";
                
                //合计
                $count['pv']['pv'] = $count['pv']['pv'] + $row['pv'];
                $count['pv']['pvOrder'] = $count['pv']['pvOrder'] + $row['pvOrder'];
                $count['pv']['pvPercent'] = $count['pv']['pv']>0 ? '100%' : '0%';
                $orderPercent = $count['pv']['pv']>0 ? number_format($count['pv']['pvOrder']/$count['pv']['pv'],4)*100 : 0;
                $count['pv']['orderPercent'] = $orderPercent.'%';
                $count['pv']['orderPercentInfo'] = $count['pv']['orderPercentInfo'] + $orderPercent;
                $count['pv']['num'] = $count['pv']['num']+1;
                
                $pvShowArray[$key]['code'] = $row['code'];
                $pvShowArray[$key]['name'] = $row['name'];
                $pvShowArray[$key]['pv'] = $row['pv'];
                $pvShowArray[$key]['pvPercent'] = $row['pvPercent'].'%';
                $pvShowArray[$key]['pvOrder'] = $row['pvOrder'];
                $pvShowArray[$key]['orderPercentInfo'] = $orderPercentInfo;
            }
            $this->view->pvRows = $pvShowArray;
            $this->view->countAll = $count;
            
            //导出Excel
            if ($vars['export']=='yes'){
                $exportArray = array();
                $exportNum =1;
                foreach ($pvShowArray as $row){
                    $exportNum++;
                    $exportArray['pv']['A'.$exportNum]= $row['name'];
                    $exportArray['pv']['B'.$exportNum]= $row['pv'];
                    $exportArray['pv']['C'.$exportNum]= $row['pvPercent'];
                    $exportArray['pv']['D'.$exportNum]= $row['pvOrder'];
                    $exportArray['pv']['E'.$exportNum]= $row['orderPercentInfo'];
                }
                $exportNum = $exportNum+1;
                $exportArray['pv']['A'.$exportNum]= '总计';
                $exportArray['pv']['B'.$exportNum]= $count['pv']['pv'];
                $exportArray['pv']['C'.$exportNum]= $count['pv']['pvPercent'];
                $exportArray['pv']['D'.$exportNum]= $count['pv']['pvOrder'];
                $exportArray['pv']['E'.$exportNum]= $count['pv']['orderPercent'];
                                
                $table = array();
                $table[0]['tableName'] = '转化率-按渠道(pv)';
                $table[0]['title'] = array('渠道名称','访问次数','访问次数占比(%)','提交订单数量','提交订单转化率');
                $table[0]['con'] = $exportArray['pv'];
                $this->_model->excelExport($table,"[{$vars['startTime']}_{$vars['endTime']}]{$productCode}-member-export");
            }
            
            
        } elseif ($vars['doType']==2){ //按专题
           
        } elseif ($vars['doType']==3){ //按操作系统
            
        } elseif ($vars['doType']==4){ //按地域
            
        } else {
            exit("未法操作");
        }
        $this->view->title = '转化率';
        $this->view->vars = $vars;
    }
    
    
    /*
     * 转化率按渠道 展开
     */
    public function getdataCountWapAction()
    {
        $vars = array();
        $wheres = array();
        $vars['startTime'] = trim($this->_request->get('startTime'));
        $vars['endTime'] = trim($this->_request->get('endTime'));
        $memberName = trim($this->_request->get('name'));
        $code = trim($this->_request->get('code'));
        $doType = trim($this->_request->get('flag'));
        
        $productCode = Application_Model_UserLogin::getInstance()->getUserCurrentProductCode();
        $wheres[] = "`productCode` = '{$productCode}'";
        
        if ($vars['startTime'] != '') {
            $wheres[] = "`date` >= '{$vars['startTime']}' ";
        }
        if ($vars['endTime'] != '') {
            $wheres[] = "`date` <= '{$vars['endTime']}' ";
        }
        
        $orderBy = "`pv` DESC";
        
        
        $where = count($wheres) > 0 ? ' WHERE ' . implode(' AND ', $wheres) . ' ' : '';
        $dayDataWapModel = new Application_Model_DayDataWap();
        $leftSql = '';
        if ($memberName == '未知'){
            $leftSql = " c.name IS NULL ";
        } elseif ($memberName == '其他'){
            $leftSql = " ifnull(c.code, '') in ({$code}) ";
        } else{
            $leftSql = " c.name = '{$memberName}' ";
        }
        
        $sql = "SELECT a.sourceId,a.sourceSubId,a.pv as pv,a.uv as uv,a.okOrderNum as orderPv,b.sourceName FROM (    
                SELECT productCode,sourceId,sourceSubId,sum(pv) as pv,sum(uv) as uv,sum(okOrderNum) as okOrderNum FROM `{$dayDataWapModel->getTableName()}` 
                {$where}
                GROUP BY productCode,sourceId,sourceSubId
                ) as a  
                LEFT JOIN  mob_source as b on a.productCode = b.productCode and a.sourceId=b.sourceId and a.sourceSubId=b.sourceSubId    
                LEFT JOIN mob_member as c on b.memberCode=c.code    
                WHERE {$leftSql}
                GROUP BY a.sourceId,a.sourceSubId  ";
        $orderRows = $dayDataWapModel ->getAdapter()->fetchAll($sql);
        
        
        $count = array();
        $count['pv'] = 0;
        $count['uv'] = 0;
        foreach ($orderRows as $key =>$row){
             $count['pv'] += $row['pv'];
             $count['uv'] += $row['uv'];
        }
        
        $result = "";
        if ($doType==1){
            if (count($orderRows)>0){
                $result .= "
                        <tr class=\"subject\">
                            <td >子渠道</td>
                            <td colspan=\"2\" align=\"center\">访问</td>
                            <td colspan=\"2\" align=\"center\">提交订单</td>
                        </tr>
                        <tr class=\"subject\">
                            <td>名称</td>
                            <td>次数</td>
                            <td>占比(%)</td>
                            <td>数量</td>
                            <td>转化率</td>
                        </tr>";
                
                foreach ($orderRows as $key =>$row){
                    $pvPercent = $count['pv']>0 ? number_format($row['pv']/$count['pv'],4)*100 : 0;
                    
                    //提交订单
                    $order = $row['orderPv'];
                    //提交订单  转化率
                    $orderPercent = $row['pv']>0 ? number_format($order/$row['pv'],4)*100 : 0;
                    $result .= " <tr>
                                 <td class=\"textLeft\">{$row['sourceName']}</td>
                                 <td>{$row['pv']}</td>
                                 <td>{$pvPercent}%</td>
                                 <td>{$order}</td>
                                 <td>{$orderPercent}%</td>
                                 </tr>
                    ";
                }
            }
        } elseif ($doType==2){
        if (count($orderRows)>0){
                $result .= "
                        <tr class=\"subject\">
                            <td >子渠道</td>
                            <td colspan=\"2\" align=\"center\">启动</td>
                            <td colspan=\"2\" align=\"center\">提交订单</td>
                        </tr>
                        <tr class=\"subject\">
                            <td>名称</td>
                            <td>次数</td>
                            <td>占比(%)</td>
                            <td>人数</td>
                            <td>转化率</td>
                        </tr>";
                foreach ($orderRows as $key =>$row){
                    $uvPercent = $count['uv']>0 ? number_format($row['uv']/$count['uv'],4)*100 : 0;
                    
                    //提交订单
                    $order = $row['orderUv'];
                    //提交订单  转化率
                    $orderPercent = $row['uv']>0 ? number_format($order/$row['uv'],4)*100 : 0;
                    $result .= " <tr>
                                 <td class=\"textLeft\">{$row['sourceName']}</td>
                                 <td>{$row['uv']}</td>
                                 <td>{$uvPercent}%</td>
                                 <td>{$order}</td>
                                 <td>{$orderPercent}%</td>
                                 </tr>
                    ";
                }
            }
        }
        exit($result);
    }
    
    
    
    
    

}